git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <junkio@cox.net>
Date
Nov 2, 2005, 06:20 UTC
Message-ID
<7v8xw71sfr.fsf@assigned-by-dhcp.cox.net>

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.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * Objections?
 git-clone.sh |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

applies-to: 9c030fed625268c19d7f0838b26f742745b36085 e125c1a717bb732319596d8b792a67c2b7b15ef7

diff --git a/git-clone.sh b/git-clone.sh
index 18e692a..c27a913 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -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
Message 1 of 1 in “git-clone: do not forget to create origin branch.”
  1. git-clone: do not forget to create origin branch.Junio C Hamano, Nov 2, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.