Reputation: 17678
I usually switch branch using this command
git fetch && git checkout branch
After that, I usually check that I'm working on the branch I intended to via git info
, which would highlight the local branch I'm working on (with an asterisk * next to the branch name).
I followed the same pattern today, but somehow git remains in master branch, even after I run git fetch && git checkout branch
. There are no error logs from the command line. But after that, git info
shows something like this (local branch is still master, instead of branch threads that I wanted to switch to).
## Remote Branches:
origin/HEAD -> origin/master
origin/master
origin/threads
## Local Branches:
* master
Compare to the normal case (when git checkout branch
works as expected) - the strange thing seems to be that there are two origin/master
, the first origin/HEAD -> origin/master
seems normal; I'm not sure about the second.
There is something weird in here but I haven't figured out.
Upvotes: 3
Views: 2530
Reputation: 24040
Note that git fetch
will only pull the references as configured in your .git/config
file - it may not be getting what you expect. If you've not set up a remote tracking branch then it won't know to pull things down from the remote branch.
In addition, 'git checkout master' will always switch to your branch called master, and not what the remote master happens to be. So one you've created a branch called 'master' the above won't change it at all.
Upvotes: 0
Reputation: 17678
It looks like I got a diverged master.
Strangely, this command did not shows any error logs.
$ git fetch && git checkout threads # threads is the name of the branch
But,
$ git fetch && git checkout master
Switched to branch 'master'
Your branch and 'origin/master' have diverged,
and have 7 and 3 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
and,
$ git pull origin master
From <git_repo> # <git_repo> is the URL of the repo
* branch master -> FETCH_HEAD
Auto-merging <file> # <file> is the filename in question
CONFLICT (add/add): Merge conflict in <file>
Automatic merge failed; fix conflicts and then commit the result.
After I manually resolved the conflicts on master, now the git fetch && git checkout threads
works ok, and I can switch to the branch threads.
As to why I got a diverged master in the first, I'm not sure - perhaps as a result of some git rebase
command I didn't do properly.
Upvotes: 1