I'd like to push my current branch (hp1) with
git push
and not
git push origin hp1:team/hp1
The remote branch already exists.
My local branches:
develop master * hp1
git remote show origin tells me:
Remote branches: develop tracked master tracked team/h2 tracked team/hp1 tracked team/n1 tracked Local branches configured for 'git pull': develop merges with remote develop master merges with remote master hp1 merges with remote team/hp1 Local refs configured for 'git push': master pushes to master (up to date)
I already tried
git branch --set-upstream hp1 origin/team/hp1
and
git branch --set-upstream hp1 refs/remotes/origin/team/hp1
but both don't work.
My colleague has a local branch called as the remote branch (team/hp1) and the code above works for him. He gets at the end an additional
Local refs configured for 'git push': develop pushes to develop (up to date) master pushes to master (up to date) team/hp1 pushes to team/hp1 (up to date)
So maybe you can tell me what's wrong and how to fix it.
EDIT my config:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = ***@***:***.git [branch "master"] remote = origin merge = refs/heads/master [branch "hp1"] remote = origin merge = refs/heads/team/hp1
In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.
In case you are using the Tower Git client, pushing to a remote is very easy: simply drag your current HEAD branch in the sidebar and drop it onto the desired remote branch - or click the "Push" button in the toolbar.
Git set-upstream. The git set-upstream allows you to set the default remote branch for your current local branch. By default, every pull command sets the master as your default remote branch.
If you run the simple command git push , Git will by default choose two more parameters for you: the remote repository to push to and the branch to push. By default, Git chooses origin for the remote and your current branch as the branch to push.
First of all, when pushing for the first time, do:
git push -u origin hp1:team/hp1
About -u option:
-u
--set-upstreamFor every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1).
Note from the manual that, this in itself will not determine what happens when you do git push
the next time. When you do git pull
while in this branch, it will fetch it from the upstream that you have set. But when you push, it will push to a matching branch ( in this case hp1 and not team/hp1)
For that to work, you have to set push.default
config value to upstream
. Once you set that, when you push from a branch ( just do git push
), it will push to the upstream as mentioned by branch.<name>.merge
So do:
git config push.default upstream
About push.default:
push.default
Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:
nothing - do not push anything.
matching - push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
upstream - push the current branch to its upstream branch.
tracking - deprecated synonym for upstream.
current - push the current branch to a branch of the same name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With