git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] remote: resolve "simple" @{push} when pushing to another remote

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 31, 2026, 08:04 UTC
Message-ID
<c58afcc4b166d33489feee41d57e65738581a0da.1793433841.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2466.v2.git.git.1793433841.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>

With push.default left at "simple", a branch whose upstream is on one remote and whose push remote is another gets pushed by "git push" to a branch of the same name on the push remote. But @{push} for that branch fails with "cannot resolve 'simple' push to a single destination". As a result "git status" shows the "git push" hint under the comparison with the upstream, even though "git push" goes elsewhere, and leaves out the comparison with the push branch when status.compareBranches asks for it.

"git push" learned to handle "simple" this way in ed2b18292b (push: change `simple` to accommodate triangular workflows, 2013-06-19). When @{push} was added in e291c75a95 (remote.c: add branch_get_push, 2015-05-21), its "simple" case only covered pushing back to the remote the branch is fetched from, where the upstream must have the same name.

Make @{push} follow "git push". When the push remote is not the remote of the branch, resolve to the branch of the same name on the push remote, as "current" does.

The test added in 9bf9eed093 (remote: fix leak in branch_get_push_1() with invalid "simple" config, 2026-01-19) relied on a different push remote being invalid for "simple". Use an upstream with a different name on the same remote instead, so that it still exercises the error path.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
 remote.c                  | 13 ++++++++-----
 t/for-each-ref-tests.sh   |  4 +++-
 t/t1514-rev-parse-push.sh | 13 ++++++++++++-
 3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/remote.c b/remote.c
index d15d34aad7..98665a3085 100644
--- a/remote.c
+++ b/remote.c
@@ -1972,16 +1972,19 @@ static char *branch_get_push_simple(struct repository *repo,
 				    struct branch *branch,
 				    struct strbuf *err)
 {
-	const char *up;
+	const char *up = NULL;
 	char *cur;
 
-	up = branch_get_upstream(branch, err);
-	if (!up)
-		return NULL;
+	if (!strcmp(remote->name,
+		    remotes_remote_for_branch(repo->remote_state, branch, NULL))) {
+		up = branch_get_upstream(branch, err);
+		if (!up)
+			return NULL;
+	}
 	cur = tracking_for_push_dest(repo, remote, branch->refname, err);
 	if (!cur)
 		return NULL;
-	if (strcmp(cur, up)) {
+	if (up && strcmp(cur, up)) {
 		free(cur);
 		return error_buf(err,
 				 _("cannot resolve 'simple' push to a single destination"));
diff --git a/t/for-each-ref-tests.sh b/t/for-each-ref-tests.sh
index b1a10dd933..4991a82b91 100644
--- a/t/for-each-ref-tests.sh
+++ b/t/for-each-ref-tests.sh
@@ -1745,9 +1745,11 @@ test_expect_success ':remotename and :remoteref' '
 '
 
 test_expect_success '%(push) with an invalid push-simple config' '
+	test_when_finished "git config branch.main.merge refs/heads/main" &&
+	git config branch.main.merge refs/heads/not-main &&
 	echo "refs/heads/main " >expect &&
 	git -c push.default=simple \
-	    -c remote.pushdefault=myfork \
+	    -c remote.pushdefault=origin \
 	    for-each-ref \
 	    --format="%(refname) %(push)" refs/heads/main >actual &&
 	test_cmp expect actual
diff --git a/t/t1514-rev-parse-push.sh b/t/t1514-rev-parse-push.sh
index 5a4f16867a..dc2df7eb80 100755
--- a/t/t1514-rev-parse-push.sh
+++ b/t/t1514-rev-parse-push.sh
@@ -39,7 +39,7 @@ test_expect_success '@{push} with default=simple' '
 	resolve main@{pUSh} refs/remotes/origin/main
 '
 
-test_expect_success 'triangular @{push} fails with default=simple' '
+test_expect_success '@{push} with default=simple fails when upstream has a different name' '
 	test_config push.default simple &&
 	test_must_fail git rev-parse topic@{push}
 '
@@ -60,6 +60,17 @@ test_expect_success '@{push} with pushremote defined' '
 	resolve topic@{push} refs/remotes/other/topic
 '
 
+test_expect_success 'triangular @{push} with default=simple and remote.pushdefault' '
+	test_config push.default simple &&
+	test_config remote.pushdefault other &&
+	test_when_finished "git checkout main" &&
+	git checkout topic &&
+	test_commit simple-triangular &&
+	git push &&
+	resolve topic@{push} refs/remotes/other/topic &&
+	test_cmp_rev topic topic@{push}
+'
+
 test_expect_success '@{p} is short for @{push}' '
 	test_config push.default current &&
 	test_config branch.topic.pushremote other &&
-- 
gitgitgadget
Previous: Harald Nordgren via GitGitGadget
Message 8 of 8 in “remote: resolve "simple" @{push} when pushing to another remote”
  1. remote: resolve "simple" @{push} when pushing to another remoteHarald Nordgren via GitGitGadget, Oct 27, 2026
  2. D. Ben KnobleOct 28, 2026
  3. Harald NordgrenOct 29, 2026
  4. Junio C HamanoOct 29, 2026
  5. Harald NordgrenOct 29, 2026
  6. 0/2 remote: resolve "simple" @{push} when pushing to another remoteHarald Nordgren via GitGitGadget, Oct 31, 2026
  7. 1/2 remote: move "simple" @{push} resolution into a helperHarald Nordgren via GitGitGadget, Oct 31, 2026
  8. 2/2 remote: resolve "simple" @{push} when pushing to another remoteHarald Nordgren via GitGitGadget, Oct 31, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.