Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout master does not switch branch - repository broken?

Tags:

tl;dr: git checkout master does not switch to master branch, gives no error or any output at all and I have no clue why. Any other branch works fine.

I have a git repository that consists of the branches development and master. I do a fresh clone of the repository, checking out branch development as default.

$ git clone <REPO-URL> --branch development $ git branch -a * development origin/HEAD -> origin/development origin/development origin/master $ git show-ref  656c781c2affc26792f857baf8e232de07101535 refs/heads/development 656c781c2affc26792f857baf8e232de07101535 refs/remotes/origin/HEAD 656c781c2affc26792f857baf8e232de07101535 refs/remotes/origin/development cfee1a1761642453edf5d001565f23b50243ff09 refs/remotes/origin/master 

The ref master is pointing to is correct, that commit does exists and is the latest commit of my master branch.

So far everything looks normal, but when I try to switch to master this is happening:

$ git checkout master $ git branch  * development 

No message from checkout, no error, nothing, and the branch is not switched.

Things I have tried so far:

  • Creating a second branch master2 from the same commit => checkout works fine.
  • Deleting and re-creating branch master both local and on origin => again no checkout possible
  • git checkout -b master --track origin/master => works, but I think it should not be necessary to use this command as this is what git checkout master should do automatically
  • Committing and pushing to master works, but does not change the checkout problem
  • I tried several git versions (1.9, 2.2) and machines (linux, windows), problem occurs everywhere.

Any further ideas? What am I missing? Is my repository broken? How can I fix this?

like image 223
schrom Avatar asked Dec 15 '15 11:12

schrom


People also ask

Does git checkout switch to a branch?

Currently, the all-encompassing command – git checkout does many things. It can be used to switch branches and also to restore the working tree files.

How do I force checkout to another branch?

Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.

Does git checkout change remote?

In summation, git checkout , when used on branches, alters the target of the HEAD ref. It can be used to create branches, switch branches, and checkout remote branches. The git checkout command is an essential tool for standard Git operation. It is a counterpart to git merge .


1 Answers

If your repo has a folder or file name the same as a branch name then you will need to: git checkout xyz -- with the extra -- at the end. It tells git to use a branch or commit instead of trying to use a folder/file name.

Found the answer on another stackoverflow post: Git change branch when file of same name is present

like image 77
Nick Avatar answered Sep 22 '22 12:09

Nick