Skip to contentSkip to conversation

Fetch: default remote repository from config

PATCH New Santi Béjar 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fetch: default remote repository from config

If in branch "foo" and this in config:

[branch "foo"]
remote=bar

"git fetch" = "git fetch bar"
"git pull" = "git pull bar"

---
 Documentation/config.txt |    3 +++
 git-fetch.sh             |   11 ++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
Documentation/config.txt +3 -0
index bb2fbc3..fa20e28 100644
@@ -119,6 +119,9 @@ apply.whitespace::
 	Tells `git-apply` how to handle whitespaces, in the same way
 	as the '--whitespace' option. See gitlink:git-apply[1].
 
+branch.<name>.remote::
+	When in branch <name>, it tells `git pull` which remote to fetch.
+
 pager.color::
 	A boolean to enable/disable colored output when the pager is in
 	use (default is true).
git-fetch.sh +6 -5
index 09a5d6c..e3b8f26 100755
@@ -68,11 +68,12 @@ done
 
 case "$#" in
 0)
-	test -f "$GIT_DIR/branches/origin" ||
-		test -f "$GIT_DIR/remotes/origin" ||
-			git-repo-config --get remote.origin.url >/dev/null ||
-				die "Where do you want to fetch from today?"
-	set origin ;;
+	curr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
+	origin=$(git-repo-config --get "branch.$curr_branch.remote")
+	origin=${origin:-origin}
+	test -n "$(get_remote_url ${origin})" ||
+		die "Where do you want to fetch from today?"
+	set x $origin ; shift ;;
 esac
 
 remote_nick="$1"
Signature · 1 line
1.4.2.1.g4b5cd