i checked out a remote branch like git checkout -b newBranch origin/some-remote-branch
but whenever i do a push it is pushed to a new branch newBranch
. How do I tell git to automatically push to the branch I checked out from origin?

- 4,102
- 5
- 23
- 37

- 4,709
- 12
- 62
- 106
-
possible duplicate of [How do you make an existing Git branch track a remote branch?](http://stackoverflow.com/questions/520650/how-do-you-make-an-existing-git-branch-track-a-remote-branch) – asermax Oct 21 '13 at 13:55
2 Answers
git push origin newBranch:some-remote-branch
Or if you want it to do it automatically when you run git push
, edit the entry in your .git/config
to read as follows
[branch "newBranch"]
remote = origin
merge = refs/heads/some-remote-branch
You can also run git branch -u origin/some-remote-branch newBranch
instead of editing .git/config
manually.
And make sure you also have the following setting, so that push will push to the upstream by default (right now, the default is to push to the matching branchname):
[push]
default = upstream
You can run git config push.default upstream
to set this, or git config --global push.default upstream
if you want to set this option globally for all of your repositories.

- 322,767
- 57
- 360
- 340
If you only want the branch to push to specific remote branch, you need to set the upstream branch with git branch -u origin/some-remote-branch
. Then you will only need to run git push
If it is always pushing to newBranch
, I think that you are doing git push origin newBranch
. This command pushes a new remote branch newBranch
onto origin.

- 41,516
- 7
- 68
- 87