Someone else on my team created a new git branch, committed and pushed to the usual remote that we work with. When I try to check out this branch, I get this:
% git checkout 12382 fatal: Cannot switch branch to a non-commit '12382'
I have not had trouble checking out other branches from this repository; tried checking another one out right after this (one that I did not have a local copy of), and it worked fine.
I tried building a server with this branch on our Go pipeline, it worked fine - which means the server was successful in checking out that branch.
Tried this to check the status of things:
% git remote show origin * remote origin Fetch URL: [email protected]:mycompany/myrepository.git Push URL: [email protected]:mycompany/myrepository.git HEAD branch: stage Remote branches: 10112 tracked 10198 tracked 10678 tracked ... 12382 tracked <<<--- ... Local branches configured for 'git pull': ... Local refs configured for 'git push': ...
Could anyone suggest how to fix this? What went wrong?
when you switch to a branch without committing changes in the old branch, git tries to merge the changes to the files in the new branch. If merging is done without any conflict, swithing branches will be successful and you can see the changes in the new branch.
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.
Git is confused, because 12382
looks like a commit hash. Use the fully qualified name to checkout the branch:
git checkout refs/heads/12382 --
or, if it's a remote branch:
git checkout refs/remotes/origin/12382 --
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With