Git checkout branch but stays in master

I usually switch branch using this command

git fetch && git checkout branch

      

After that, I usually check that I am working on the branch I intended with a help git info

that allocates the local branch I am working on (with an asterisk * next to the branch name).

I followed the same pattern today, but somehow git stays on the master branch even after running git fetch && git checkout branch

. There are no error logs on the command line. But after that it git info

shows something like this (the local branch is still master , instead of the threads I wanted to switch to).

    ## Remote Branches:

    origin/HEAD -> origin/master
    origin/master
    origin/threads

    ## Local Branches:

    * master

      

Compare with the usual case (when it git checkout branch

works as expected) - strange, it seems that there are two origin/master

, the first origin/HEAD -> origin/master

seems to be normal; I'm not sure about the second.

There is something strange here, but I didn't get it.

+3


source to share


2 answers


Looks like I have a divergent master.

Strangely, this command didn't show 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 conflicts on master , it now git fetch && git checkout threads

works fine and I can switch to branch...

As for why I got the divergent master in the beginning , I'm not sure - maybe as a result of some command git rebase

I didn't get it right.

+1


source


Note that this git fetch

will only pull links as configured in your file .git/config

- you may not get what you expect. If you haven't set up a remote tracking branch, then it won't know what to pull from the remote branch.



Also, the "git checkout master" always switches to your branch named master, not what happens to the remote master. So you created a branch named "master" above, don't change it at all.

0


source







All Articles