Home > Mobile >  automatically create --set-upstream origin doing git push
automatically create --set-upstream origin doing git push

Time:01-13

It's annoying I got prompt every time trying to push new branch. For instance, I do this

git checkout -b myBranch
git add . && git commit -m 'first commit'
git push

but I got this

git push --set-upstream origin myBranch

is there anyway to skip this?

CodePudding user response:

I don't think there's a way to skip it when pushing a new branch, but there is a shortcut to do this:

git push -u origin HEAD

where HEAD means current branch (assuming you are using git version 2.x; it's different in version 1.x).

Furthermore, you can set it to an alias using git config alias.pushhead 'push -u origin HEAD'. Then, you can use command git pushhead instead.

CodePudding user response:

You can configure Git with these settings:

git config --global push.default current
git config --global remote.pushDefault origin

and then you can simply use:

git push

to push the curent branch to a branch with the same name on the remote origin. This does not set the upstream configuration, but it does allow you to push without any other arguments, whether it’s the first time you are pushing a branch or not.

  •  Tags:  
  • Related