Skip to contentSkip to conversation

git-clone: do not forget to create origin branch.

PATCH New Junio C Hamano 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-clone: do not forget to create origin branch.

The newly cloned repository by default had .git/remotes/origin set up to track the remote master to origin, but forgot to create the origin branch ourselves. Also it hardcoded the assumption that the remote HEAD points at "master", which may not always be true.

---

* Objections?

 git-clone.sh |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

applies-to: 9c030fed625268c19d7f0838b26f742745b36085 e125c1a717bb732319596d8b792a67c2b7b15ef7

git-clone.sh +11 -4
index 18e692a..c27a913 100755
@@ -196,10 +196,17 @@ cd $D || exit
 
 if test -f ".git/HEAD"
 then
-	mkdir -p .git/remotes || exit
-	echo >.git/remotes/origin \
-	"URL: $repo
-Pull: master:origin"
+	head_points_at=`git-symbolic-ref HEAD`
+	case "$head_points_at" in
+	refs/heads/*)
+		head_points_at=`expr "$head_points_at" : 'refs/heads/\(.*\)'`
+		mkdir -p .git/remotes &&
+		echo >.git/remotes/origin \
+		"URL: $repo
+Pull: $head_points_at:origin"
+		cp ".git/refs/heads/$head_points_at" .git/refs/heads/origin
+	esac
+
 	case "$no_checkout" in
 	'')
 		git checkout

---
0.99.9.GIT