Skip to content

Commit 224c217

Browse files
artagnongitster
authored andcommitted
remote.c: introduce remote.pushdefault
This new configuration variable defines the default remote to push to, and overrides `branch.<name>.remote` for all branches. It is useful in the typical triangular-workflow setup, where the remote you're fetching from is different from the remote you're pushing to. Signed-off-by: Ramkumar Ramachandra <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f24f715 commit 224c217

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Documentation/config.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,12 @@ branch.autosetuprebase::
727727
This option defaults to never.
728728

729729
branch.<name>.remote::
730-
When in branch <name>, it tells 'git fetch' and 'git push' which
731-
remote to fetch from/push to. It defaults to `origin` if no remote is
732-
configured. `origin` is also used if you are not on any branch.
730+
When on branch <name>, it tells 'git fetch' and 'git push'
731+
which remote to fetch from/push to. The remote to push to
732+
may be overridden with `remote.pushdefault` (for all branches).
733+
If no remote is configured, or if you are not on any branch,
734+
it defaults to `origin` for fetching and `remote.pushdefault`
735+
for pushing.
733736

734737
branch.<name>.merge::
735738
Defines, together with branch.<name>.remote, the upstream branch
@@ -1898,6 +1901,10 @@ receive.updateserverinfo::
18981901
If set to true, git-receive-pack will run git-update-server-info
18991902
after receiving data from git-push and updating refs.
19001903

1904+
remote.pushdefault::
1905+
The remote to push to by default. Overrides
1906+
`branch.<name>.remote` for all branches.
1907+
19011908
remote.<name>.url::
19021909
The URL of a remote repository. See linkgit:git-fetch[1] or
19031910
linkgit:git-push[1].

remote.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,16 @@ static int handle_config(const char *key, const char *value, void *cb)
389389
add_instead_of(rewrite, xstrdup(value));
390390
}
391391
}
392+
392393
if (prefixcmp(key, "remote."))
393394
return 0;
394395
name = key + 7;
396+
397+
/* Handle remote.* variables */
398+
if (!strcmp(name, "pushdefault"))
399+
return git_config_string(&pushremote_name, key, value);
400+
401+
/* Handle remote.<name>.* variables */
395402
if (*name == '/') {
396403
warning("Config remote shorthand cannot begin with '/': %s",
397404
name);

t/t5516-fetch-push.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,18 @@ test_expect_success 'push with config remote.*.push = HEAD' '
497497
check_push_result testrepo $the_first_commit heads/local
498498
'
499499

500+
test_expect_success 'push with remote.pushdefault' '
501+
mk_test up_repo heads/master &&
502+
mk_test down_repo heads/master &&
503+
test_config remote.up.url up_repo &&
504+
test_config remote.down.url down_repo &&
505+
test_config branch.master.remote up &&
506+
test_config remote.pushdefault down &&
507+
git push &&
508+
check_push_result up_repo $the_first_commit heads/master &&
509+
check_push_result down_repo $the_commit heads/master
510+
'
511+
500512
test_expect_success 'push with config remote.*.pushurl' '
501513
502514
mk_test testrepo heads/master &&

0 commit comments

Comments
 (0)