I have cloned a repo with 2 branches from github:
git clone https://github.com/user/repo
cd repo
when I do a git branch it only shows the master branch. Then I did a git branch -a it shows all branches.
master
remotes/origin/HEAD
remotes/origin/master
remotes/origin/develop
then I did a git checkout develop:
Branch develop set up to track remote branch develop from origin.
Switched to a new branch 'develop'
then git checkout master to go back to master branch.
Why is git checkout develop different from git checkout origin/develop (it says i’m in detached head state)?
You should have done:
From
git checkout: if you don’t specify a starting point, it starts from the currentHEAD(which wasmasterin your case, meaning your ‘develop’ branch doesn’t start from where you think it should).On the –track option, see “Git: What is a tracking branch?“.
If you want to see/track all our remote branches in your local repo, see “Track all remote git branches as local branches“.
Your starting point was master, because your git branch returned the current branch: master.
If you do a
git checkoutdevelop just there, it starts from the current branch.