Git push trying to push to different branch even though tracked
I’m currently working on
angular-routing and tried pushing to
origin/angular-routing with simply
git push which worked, but I noticed that I got the following error:
! [rejected] johndev -> johndev (non-fast-forward)
I get what the error means, that’s fine, but I don’t get why it’s trying to push there in the first place. I have all my branches tracked to the same remote branches which seems to be setup properly. Running
git remote show origin gives me the following :
Remote branches: angular-routing tracked dev tracked johndev tracked master tracked Local branches configured for 'git pull': angular-routing merges with remote angular-routing dev merges with remote dev johndev merges with remote johndev master merges with remote master Local refs configured for 'git push': angular-routing pushes to angular-routing (up to date) dev pushes to dev (up to date) johndev pushes to johndev (local out of date) master pushes to master (up to date)
As far as I can tell from this, it’s setup properly so there is no reason for my
git push on
angular-routing to be attempting to push to
johndev but it is.
What am I doing wrong here?
One Solution collect form web for “Git push trying to push to different branch even though tracked”
That is happening because of the setting of
matching, which is the default. This means that when you do a push without specifying what to push git will attempt to push all branches which already exist on the destination.
It sounds like you’d want to change that setting to
upstream, which would cause it by default to only push the current branch to the remote branch which is configured as its upstream branch. This can be done with:
git config --global push.default upstream