{"thread":{"id":"66442","subject":"[PATCH 0/2] remote: allow a list of remotes in remote.pushDefault","startedAt":"2026-10-02T07:17:54Z","lastAt":"2026-10-02T07:17:59Z","messageCount":3,"participants":["Harald Nordgren via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"553895","messageId":"pull.2423.git.git.1790925472.gitgitgadget@gmail.com","threadId":"66442","inReplyTo":null,"subject":"[PATCH 0/2] remote: allow a list of remotes in remote.pushDefault","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-02T07:17:50Z","receivedAt":"2026-10-02T07:17:54Z","isPatch":true,"body":"Let remote.pushDefault hold a space separated list of remote names and push\nto the first one configured in the repository, so a single global setting\nlike fork origin works everywhere.\n\nHarald Nordgren (2):\n  remote: factor out lookup of a remote by name\n  remote: allow a list of remotes in remote.pushDefault\n\n Documentation/config/remote.adoc |  7 +++++\n remote.c                         | 54 ++++++++++++++++++++++++--------\n t/t5516-fetch-push.sh            | 36 +++++++++++++++++++++\n 3 files changed, 84 insertions(+), 13 deletions(-)\n\n\nbase-commit: 0f8e75abebff0877cae681a3d5ff31ac47f54220\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2423%2FHaraldNordgren%2Fremote-pushdefault-list-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2423/HaraldNordgren/remote-pushdefault-list-v1\nPull-Request: https://github.com/git/git/pull/2423\n-- \ngitgitgadget\n"},{"id":"553896","messageId":"db46b1b51009ec2f9a61cc76f9a2835cd207aeda.1790925472.git.gitgitgadget@gmail.com","threadId":"66442","inReplyTo":"pull.2423.git.git.1790925472.gitgitgadget@gmail.com","subject":"[PATCH 1/2] remote: factor out lookup of a remote by name","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-02T07:17:51Z","receivedAt":"2026-10-02T07:17:56Z","isPatch":true,"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nmake_remote() looks up an existing remote in the hashmap before\ncreating a new one. Move that lookup into find_remote() so that code\nwhich only wants to know whether a remote is configured can use it\nwithout creating an entry.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n remote.c | 25 +++++++++++++++----------\n 1 file changed, 15 insertions(+), 10 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex fe62068463..6567ec91cc 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -128,23 +128,28 @@ static int remotes_hash_cmp(const void *cmp_data UNUSED,\n \t\treturn strcmp(a->name, b->name);\n }\n \n+static struct remote *find_remote(struct remote_state *remote_state,\n+\t\t\t\t  const char *name, int len)\n+{\n+\tstruct remotes_hash_key lookup = { .str = name, .len = len };\n+\tstruct hashmap_entry lookup_entry, *e;\n+\n+\thashmap_entry_init(&lookup_entry, memhash(name, len));\n+\te = hashmap_get(&remote_state->remotes_hash, &lookup_entry, &lookup);\n+\treturn e ? container_of(e, struct remote, ent) : NULL;\n+}\n+\n static struct remote *make_remote(struct remote_state *remote_state,\n \t\t\t\t  const char *name, int len)\n {\n \tstruct remote *ret;\n-\tstruct remotes_hash_key lookup;\n-\tstruct hashmap_entry lookup_entry, *e;\n \n \tif (!len)\n \t\tlen = strlen(name);\n \n-\tlookup.str = name;\n-\tlookup.len = len;\n-\thashmap_entry_init(&lookup_entry, memhash(name, len));\n-\n-\te = hashmap_get(&remote_state->remotes_hash, &lookup_entry, &lookup);\n-\tif (e)\n-\t\treturn container_of(e, struct remote, ent);\n+\tret = find_remote(remote_state, name, len);\n+\tif (ret)\n+\t\treturn ret;\n \n \tCALLOC_ARRAY(ret, 1);\n \tret->prune = -1;  /* unspecified */\n@@ -160,7 +165,7 @@ static struct remote *make_remote(struct remote_state *remote_state,\n \t\t   remote_state->remotes_alloc);\n \tremote_state->remotes[remote_state->remotes_nr++] = ret;\n \n-\thashmap_entry_init(&ret->ent, lookup_entry.hash);\n+\thashmap_entry_init(&ret->ent, memhash(name, len));\n \tif (hashmap_put_entry(&remote_state->remotes_hash, ret, ent))\n \t\tBUG(\"hashmap_put overwrote entry after hashmap_get returned NULL\");\n \treturn ret;\n-- \ngitgitgadget\n\n"},{"id":"553897","messageId":"955709d4ef3aa43a6fb15cf5007daf094b76d427.1790925472.git.gitgitgadget@gmail.com","threadId":"66442","inReplyTo":"pull.2423.git.git.1790925472.gitgitgadget@gmail.com","subject":"[PATCH 2/2] remote: allow a list of remotes in remote.pushDefault","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-02T07:17:52Z","receivedAt":"2026-10-02T07:17:59Z","isPatch":true,"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nSomeone who pushes to a personal fork in some repositories and to\norigin in others cannot set remote.pushDefault globally. Repositories\nwithout the named remote fail to push, because git takes the missing\nname for a URL.\n\nLet remote.pushDefault hold a space separated list of remote names and\npush to the first one that is configured in the repository. When none\nof them is configured, fall back to branch.<name>.remote as if the\nvariable was not set. A single name keeps working as before, and a\nvalue set in the repository still overrides one set globally.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n Documentation/config/remote.adoc |  7 +++++++\n remote.c                         | 29 ++++++++++++++++++++++---\n t/t5516-fetch-push.sh            | 36 ++++++++++++++++++++++++++++++++\n 3 files changed, 69 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config/remote.adoc b/Documentation/config/remote.adoc\nindex 3a20d0f752..6a67c97fe8 100644\n--- a/Documentation/config/remote.adoc\n+++ b/Documentation/config/remote.adoc\n@@ -2,6 +2,13 @@ remote.pushDefault::\n \tThe remote to push to by default.  Overrides\n \t`branch.<name>.remote` for all branches, and is overridden by\n \t`branch.<name>.pushRemote` for specific branches.\n++\n+The value may be a space separated list of remote names, in which case\n+the first one that is configured in the repository is used. If none of\n+them is configured, `branch.<name>.remote` is used as if\n+`remote.pushDefault` was not set. This allows setting a list such as\n+`fork origin` globally and have repositories without a `fork` remote\n+push to `origin`.\n \n remote.<name>.url::\n \tThe URL of a remote repository.  See linkgit:git-fetch[1] or\ndiff --git a/remote.c b/remote.c\nindex 6567ec91cc..3cad0673b9 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -700,6 +700,25 @@ const char *remote_for_branch(struct branch *branch, int *explicit)\n \t\t\t\t\t explicit);\n }\n \n+static const char *pushdefault_candidate(struct remote_state *remote_state)\n+{\n+\tconst char *p = remote_state->pushremote_name;\n+\n+\tif (!strchr(p, ' '))\n+\t\treturn p;\n+\n+\twhile (*p) {\n+\t\tsize_t len = strcspn(p, \" \");\n+\t\tstruct remote *remote = find_remote(remote_state, p, len);\n+\n+\t\tif (remote && valid_remote(remote))\n+\t\t\treturn remote->name;\n+\t\tp += len;\n+\t\tp += strspn(p, \" \");\n+\t}\n+\treturn NULL;\n+}\n+\n static const char *\n remotes_pushremote_for_branch(struct remote_state *remote_state,\n \t\t\t      struct branch *branch, int *explicit)\n@@ -710,9 +729,13 @@ remotes_pushremote_for_branch(struct remote_state *remote_state,\n \t\treturn branch->pushremote_name;\n \t}\n \tif (remote_state->pushremote_name) {\n-\t\tif (explicit)\n-\t\t\t*explicit = 1;\n-\t\treturn remote_state->pushremote_name;\n+\t\tconst char *name = pushdefault_candidate(remote_state);\n+\n+\t\tif (name) {\n+\t\t\tif (explicit)\n+\t\t\t\t*explicit = 1;\n+\t\t\treturn name;\n+\t\t}\n \t}\n \treturn remotes_remote_for_branch(remote_state, branch, explicit);\n }\ndiff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh\nindex b982b209bf..7a0cdafd65 100755\n--- a/t/t5516-fetch-push.sh\n+++ b/t/t5516-fetch-push.sh\n@@ -591,6 +591,42 @@ test_expect_success 'push with remote.pushdefault' '\n \tcheck_push_result down_repo $the_commit heads/main\n '\n \n+test_expect_success 'push with remote.pushdefault list picks first existing remote' '\n+\tmk_test up_repo heads/main &&\n+\tmk_test down_repo heads/main &&\n+\ttest_config remote.up.url up_repo &&\n+\ttest_config remote.down.url down_repo &&\n+\ttest_config branch.main.remote up &&\n+\ttest_config remote.pushdefault \"missing down up\" &&\n+\ttest_config push.default matching &&\n+\tgit push &&\n+\tcheck_push_result up_repo $the_first_commit heads/main &&\n+\tcheck_push_result down_repo $the_commit heads/main\n+'\n+\n+test_expect_success 'push with remote.pushdefault list of missing remotes' '\n+\tmk_test up_repo heads/main &&\n+\ttest_config remote.up.url up_repo &&\n+\ttest_config branch.main.remote up &&\n+\ttest_config remote.pushdefault \"missing also-missing\" &&\n+\ttest_config push.default matching &&\n+\tgit push &&\n+\tcheck_push_result up_repo $the_commit heads/main\n+'\n+\n+test_expect_success 'repository remote.pushdefault overrides global list' '\n+\tmk_test up_repo heads/main &&\n+\tmk_test down_repo heads/main &&\n+\ttest_config remote.up.url up_repo &&\n+\ttest_config remote.down.url down_repo &&\n+\ttest_config_global remote.pushdefault \"down up\" &&\n+\ttest_config remote.pushdefault up &&\n+\ttest_config push.default matching &&\n+\tgit push &&\n+\tcheck_push_result up_repo $the_commit heads/main &&\n+\tcheck_push_result down_repo $the_first_commit heads/main\n+'\n+\n test_expect_success 'push with config remote.*.pushurl' '\n \tmk_test testrepo heads/main &&\n \tgit checkout main &&\n-- \ngitgitgadget\n"}]}