Git push trying to push to different branch even though tracked

I’ve got a git repo setup with 4 branches:

  • master
  • dev
  • johndev
  • angular-routing

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:

  • git: how to fix commit in both branches
  • How can I retrieve commits in “overwritten” branch in Git?
  • Where am I? * (no branch)
  • How to perform merge?
  • tags and merging of branches
  • Setting up personal branch permissions using gitolite
  • ! [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?

  • Multiple heroku accounts
  • What does // refer to when you have nested Buck projects?
  • git clone in .bat script
  • How to create a branch and reset another with git?
  • Can Git or Mercurial be set to bypass the local repository and go straight to the central one?
  • What does the last line of git bisect output mean?
  • 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 push.default is 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
    
    Git Baby is a git and github fan, let's start git clone.