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

git clone operation

From
MGMike Gant <mwgant@gmail.com>
Date
Aug 17, 2008, 18:44 UTC
Message-ID
<20080817184443.GA11782@mg1.gantsfort.com>

I'm trying to understand git-clone and what to expect when I clone a repository. Disclaimer, I am a newbie :).

Assume I have a repo with the following branches:
  cpu-intfc
  gige_mux
  improve-build
  main-devel
* master

According to the man page, git-clone "creates and checks out an initial branch equal to the cloned repository's currently active branch."

So, when I clone this repo and run 'git-branch -a' I will have the following:

  origin/HEAD
  origin/cpu-intfc
  origin/gige_mux
  origin/improve-build
  origin/main-devel
  origin/master
* master
All the origin/* branches are remote.
And, .git/refs/remotes/origin/HEAD is, 

$ cat .git/refs/remotes/origin/HEAD ref: refs/remotes/origin/master

So far, this makes sense to me.

Now, let's say that I am working in the cpu-intfc branch of the original repository and I clone the repository.

Running git-branch -a returns the following
  origin/HEAD
  origin/cpu-intfc
  origin/gige_mux
  origin/improve-build
  origin/main-devel
  origin/master
* cpu-intfc
And this,

$ cat .git/refs/remotes/origin/HEAD ref: refs/remotes/origin/cpu-intfc

I was expecting to have a local branch named master (that is equal to the remote branch origin/cpu-intfc) instead of cpu-intfc. Am I wrong to expect this? Also, as a newbie user, it seems odd that I cannot specify which branch of repo that I am cloning should be the default (master) branch of the cloned repo? To put it another way, when cloning a repo I have no way of controlling which branch I get as the default. It just happens to depend on which branch the developer is working in at the time I clone. I've read through the man-page and there doesn't seem to be any way around this.

I realize that I can create a new local branch that is based off the desired branch:

$ git-checkout -b master origin/master
Is this the accepted method for obtaining the desired branch?

Thanks, Mike

Next: Jakub Narebski
Message 1 of 5 in “git clone operation”
  1. Mike GantAug 17, 2008
  2. Jakub NarebskiAug 17, 2008
  3. Björn SteinbrinkAug 17, 2008
  4. Mike GantAug 20, 2008
  5. Mike GantAug 20, 2008

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.