When I execute
git checkout remotes/origin/test_branch
my HEAD goes in a detached state. Below is output:
C:\..\git_test>git checkout remotes/origin/test_branch
Note: checking out 'remotes/origin/test_branch'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 4590fa2 Test branch commit
M src/test/resources/**
C:\..\git_test>git branch -a
* (HEAD detached at origin/test_branch)
test_branch
master
remotes/origin/HEAD -> origin/master
remotes/origin/test_branch
remotes/origin/master
And if I execute
git checkout test_branch
on the same branch then I am no more in a detached state.
C:\..\git_test>git checkout test_branch
Switched to branch 'test_branch'
M src/test/resources/**
Your branch is up to date with 'origin/test_branch'.
C:\..\git_test>git branch -a
* test_branch
master
remotes/origin/HEAD -> origin/master
remotes/origin/test_branch
remotes/origin/master
Please can anyone explain what is the difference and why it is going to the detached state while the branch is same?