Skip to main content

I reproduced this just now by accident:I reproduced this just now by accident:

  1. lists the remote branches

     git branch -r
           origin/Feature/f1234
           origin/master
    
  2. I want to checkout one locally, so I cut paste:

     git checkout origin/Feature/f1234
    
  3. Presto! Detached HEAD state

     You are in 'detached HEAD' state. [...])
    
  origin/Feature/f1234
  origin/master
  1. I want to checkout one locally, so I cut paste:

     git checkout origin/Feature/f1234
    
 

Presto! Detached HEAD state (git prompts you the message "You are in 'detached HEAD' state. [...]").Solution #1:

See what I did there? I shouldDo not have included "include origin/" at the front of my branch spec when I was checking it out.:

git checkout Feature/f1234

Solution #2:

Add -b parameter which creates a local branch from the remote

git checkout -b origin/Feature/f1234 or

git checkout -b Feature/f1234 it will fall back to origin automatically

I reproduced this just now by accident:

  1. lists the remote branches

     git branch -r
    
  origin/Feature/f1234
  origin/master
  1. I want to checkout one locally, so I cut paste:

     git checkout origin/Feature/f1234
    

Presto! Detached HEAD state (git prompts you the message "You are in 'detached HEAD' state. [...]").

See what I did there? I should not have included "origin/" at the front of my branch spec when I was checking it out.

I reproduced this just now by accident:

  1. lists the remote branches

     git branch -r
           origin/Feature/f1234
           origin/master
    
  2. I want to checkout one locally, so I cut paste:

     git checkout origin/Feature/f1234
    
  3. Presto! Detached HEAD state

     You are in 'detached HEAD' state. [...])
    
 

Solution #1:

Do not include origin/ at the front of my branch spec when checking it out:

git checkout Feature/f1234

Solution #2:

Add -b parameter which creates a local branch from the remote

git checkout -b origin/Feature/f1234 or

git checkout -b Feature/f1234 it will fall back to origin automatically

code formatting
Source Link
Adriano
  • 19.9k
  • 19
  • 104
  • 140

I reproduced this just now by accident:

git branch -r

origin/Feature/f1234
origin/master

  1. lists the remote branches

     git branch -r
    

lists the remote branches - I want to checkout one locally, so I cut paste:

  origin/Feature/f1234
  origin/master

git checkout origin/Feature/f1234

  1. I want to checkout one locally, so I cut paste:

     git checkout origin/Feature/f1234
    

Presto! Detached HEAD state (git prompts you the message "You are in 'detached HEAD' state. [...]").

See what I did there? I should not have included "origin/"origin/" at the front of my branch spec when I was checking it out.

I reproduced this just now by accident:

git branch -r

origin/Feature/f1234
origin/master

lists the remote branches - I want to checkout one locally, so I cut paste:

git checkout origin/Feature/f1234

Presto! Detached HEAD state.

See what I did there? I should not have included "origin/" at the front of my branch spec when I was checking it out.

I reproduced this just now by accident:

  1. lists the remote branches

     git branch -r
    
  origin/Feature/f1234
  origin/master
  1. I want to checkout one locally, so I cut paste:

     git checkout origin/Feature/f1234
    

Presto! Detached HEAD state (git prompts you the message "You are in 'detached HEAD' state. [...]").

See what I did there? I should not have included "origin/" at the front of my branch spec when I was checking it out.

Source Link
Owen
  • 2k
  • 1
  • 14
  • 9

I reproduced this just now by accident:

git branch -r

origin/Feature/f1234
origin/master

lists the remote branches - I want to checkout one locally, so I cut paste:

git checkout origin/Feature/f1234

Presto! Detached HEAD state.

See what I did there? I should not have included "origin/" at the front of my branch spec when I was checking it out.