git pull from wrong remote branch
-
14-06-2021 - |
Question
My origin has a fixes
and a fixes_v3
branch. My client has just fixes
. I do a git pull git+ssh:/.../mygitrepo
and suddenly on my client I have all the fixes_v3
code in the fixes
branch. Why on earth did this happen? Now I try git pull ... mygitrepo fixes
and it just tells me it's up to date.
git remote show origin
gives this:
HEAD branch: fixes
Local refs configured for 'git push':
fixes pushes to fixes (fast-forwardable)
master pushes to master (up to date)
Solution
Apparently your branches are tracking the false remotes. Do a git remote show origin
to see which branch remote branch fixes
merges. It probably will say something like
fixes merges with remote fixes_v3
Adjust this accordingly after undoing your last merge.
OTHER TIPS
The quick fix?
Undo all local commits. E.g.
Select branch for undo
git branch fixes
Remove local commits
git reset --hard origin/fixes
How did the topic branch get messed up?
In my case, I'd done a pull without naming the destination:
git pull origin cifs_support
Since there was no local cifs_support
branch, the commits from origin/cifs_support
were added to master
.
Are you safe?
No. Check your config using the advice in the accepted answer: use git remote show origin
to see which branches are affected by git pull
and git push
. If branch tracking is wrong, fix it ASAP.