Search code examples
gitgithubgit-push

Git push on new local branch updates master instead of creating new remote branch


Problem: When my co-worker tries to push a new local branch to the repository, a new remote branch is not created. Instead, the commit from the local branch is pushed directly to the master branch.

Example Code:

$ git checkout -b newBranch origin/master
<make change to file>
$ git commit -am"newBranch commit message"
$ git push origin newBranch

Instead of getting the expected message ending with

* [new branch]      newBranch -> newBranch

my co-worker gets a message ending with this

deee5b8..756bf15  newBranch -> master

I tested this exact process on my machine and it worked just as expected; a new remote branch was created in the repository after the push.

This behavior is repeatable across multiple repositories and happens every time he tries to push a new branch to the repo. If the branch already exists on the repo, the commit is pushed to the branch as expected.

I'm assuming the difference is a setting or config option on my co-worker's machine, but I have been unable to identify the culprit. Hoping someone else has run into this before. Just let me know if I left out any key information. Thanks.


Solution

  • No doubt he has push.default set to upstream (as a --global configuration item; technically it could also be --system but that's much less likely). He might want to use simple instead. See the git config documentation (under "variables", very long list).