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

Re: remote branch checkout issue, why its *(no branch)

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 28, 2008, 22:32 UTC
Message-ID
<m3k5anjxcd.fsf@localhost.localdomain>
In-Reply-To
<9e6474ae0811281415n7b4596afq7b3ce25816d9a639@mail.gmail.com>
"Sudipta GHOSH" <sudipta.in@gmail.com> writes:
Show 17 quoted lines
> In our git repository there are few branches like
> 
> master
> origin/B1
> origin/B2
> 
> After doing  #git checkout origin/B1 I found that my current branch is
> *(no branch)
> 
> #git branch
> *(no branch)
> master
> 
> Why its showing *(no branch) why not origin/B1
> 
> How I can checkout origin/B1 and after that my current branch will be
> origin/B1 not the *(no branch)

First, 'origin/B1' is so called remote-tracking branch, and its full name is refs/remotes/origin/B1. Those branches are updated _automatically_ by git on fetch, to follow branch 'B1' in 'origin' repository. Therefore, to not lose _your_ changes git doesn't allow checking out remote-tracking branches. You can checkout _state_ of such branch into anonymous noname branch, so called in git jargon "detached HEAD".

What you can do is to create _local_ branch, closely tied to remote-tracking branch 'origin/B1', by using:

  $ git branch -b B1 --track origin/B1

Git would set up configuration for this branch in such way that "git pull" command given on 'B1' branch would "do the right thing"(TM)

I really recommend reading "Git User's Manual" or "The Git Community Book" first...

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Sudipta GHOSHNext: Björn Steinbrink
Message 2 of 3 in “remote branch checkout issue, why its *(no branch)”
  1. Sudipta GHOSHNov 28, 2008
  2. Jakub NarebskiNov 28, 2008
  3. Björn SteinbrinkNov 28, 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.