Skip to content

Commit 9f765ce

Browse files
artagnongitster
authored andcommitted
remote.c: introduce branch.<name>.pushremote
This new configuration variable overrides `remote.pushdefault` and `branch.<name>.remote` for pushes. When you pull from one place (e.g. your upstream) and push to another place (e.g. your own publishing repository), you would want to set `remote.pushdefault` to specify the remote to push to for all branches, and use this option to override it for a specific branch. Signed-off-by: Ramkumar Ramachandra <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 224c217 commit 9f765ce

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Documentation/config.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,19 @@ branch.<name>.remote::
730730
When on branch <name>, it tells 'git fetch' and 'git push'
731731
which remote to fetch from/push to. The remote to push to
732732
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.
733+
The remote to push to, for the current branch, may be further
734+
overridden by `branch.<name>.pushremote`. If no remote is
735+
configured, or if you are not on any branch, it defaults to
736+
`origin` for fetching and `remote.pushdefault` for pushing.
737+
738+
branch.<name>.pushremote::
739+
When on branch <name>, it overrides `branch.<name>.remote` for
740+
pushing. It also overrides `remote.pushdefault` for pushing
741+
from branch <name>. When you pull from one place (e.g. your
742+
upstream) and push to another place (e.g. your own publishing
743+
repository), you would want to set `remote.pushdefault` to
744+
specify the remote to push to for all branches, and use this
745+
option to override it for a specific branch.
736746

737747
branch.<name>.merge::
738748
Defines, together with branch.<name>.remote, the upstream branch
@@ -1903,7 +1913,8 @@ receive.updateserverinfo::
19031913

19041914
remote.pushdefault::
19051915
The remote to push to by default. Overrides
1906-
`branch.<name>.remote` for all branches.
1916+
`branch.<name>.remote` for all branches, and is overridden by
1917+
`branch.<name>.pushremote` for specific branches.
19071918

19081919
remote.<name>.url::
19091920
The URL of a remote repository. See linkgit:git-fetch[1] or

remote.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ static int handle_config(const char *key, const char *value, void *cb)
364364
default_remote_name = branch->remote_name;
365365
explicit_default_remote_name = 1;
366366
}
367+
} else if (!strcmp(subkey, ".pushremote")) {
368+
if (branch == current_branch)
369+
if (git_config_string(&pushremote_name, key, value))
370+
return -1;
367371
} else if (!strcmp(subkey, ".merge")) {
368372
if (!value)
369373
return config_error_nonbool(key);

t/t5516-fetch-push.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,21 @@ test_expect_success 'push with config remote.*.pushurl' '
519519
check_push_result testrepo $the_commit heads/master
520520
'
521521

522+
test_expect_success 'push with config branch.*.pushremote' '
523+
mk_test up_repo heads/master &&
524+
mk_test side_repo heads/master &&
525+
mk_test down_repo heads/master &&
526+
test_config remote.up.url up_repo &&
527+
test_config remote.pushdefault side_repo &&
528+
test_config remote.down.url down_repo &&
529+
test_config branch.master.remote up &&
530+
test_config branch.master.pushremote down &&
531+
git push &&
532+
check_push_result up_repo $the_first_commit heads/master &&
533+
check_push_result side_repo $the_first_commit heads/master &&
534+
check_push_result down_repo $the_commit heads/master
535+
'
536+
522537
test_expect_success 'push with dry-run' '
523538
524539
mk_test testrepo heads/master &&

0 commit comments

Comments
 (0)