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

git clone does not checkout active branch

From
UUdo <u.offermann@gmail.com>
Date
Aug 3, 2011, 16:56 UTC
Message-ID
<loom.20110803T185528-8@post.gmane.org>

I have a remote bare repository with two branches 'master' and 'testing', where HEAD refers to 'testing'. When cloning this repository git checks out 'master', if 'master' and 'testing' are on the same revision (i.e. HEAD == testing == master). Only if 'testing' is one (or more) commit(s) behind or ahead, git clone checks out the 'testing' branch on the local side. I tried this with git 1.7.5 on Mac OS X (10.6.8).

Addendum: I just tried the same with a non-bare repository:

mkdir A cd A git init touch a git add a git commit -m "init repo A with a" git checkout -b testing

now back in the root dir:
cd ..
git clone A B
cd B
git branch -v -a
* master                 28f599b init A
  remotes/origin/HEAD    -> origin/master
  remotes/origin/master  28f599b init A
  remotes/origin/testing 28f599b init A
it's 'master'! Back to repo A (we are still in branch 'testing'):

cd ../A touch b git add b git commit -m "add b in branch testing"

now 'testing' is one commit ahead 'master'. Now let's clone A again:
cd ..
git clone A C
cd C
git branch -a -v
* testing                23bca39 add b in branch testing
  remotes/origin/HEAD    -> origin/testing
  remotes/origin/master  28f599b init A
  remotes/origin/testing 23bca39 add b in branch testing

You can re-verify this weird behavior by going back to A, checkout 'master' and merge it with 'testing' (so that all branches have the same head). Now clone A into D and D will be checked out on master!

Next: Jeff King
Message 1 of 2 in “git clone does not checkout active branch”
  1. UdoAug 3, 2011
  2. Jeff KingAug 3, 2011

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.