2

my workflow currently after checkout -b <new_branch> from master, I will push to <new_branch>, but one thing annoy me is that git force me to do

git push --set-upstream origin <new_branch>

how can I skip it by default? I don't see the point of doing that.

Nadiely Jade
  • 135
  • 7
  • There are [multiple plus points for setting an upstream](https://stackoverflow.com/q/37770467/1256452), but if you have no interest in any of them, see [Dev-vruper's answer]. – torek Dec 14 '20 at 20:21

2 Answers2

3

From the Git Push.Default Documentation ,

Defines the action git push should take if no refspec is given (whether from the command-line, config, or elsewhere). Different values are well-suited for specific workflows; for instance, in a purely central workflow (i.e. the fetch source is equal to the push destination), upstream is probably what you want. Possible values are:

nothing - do not push anything (error out) unless a refspec is given. This is primarily meant for people who want to avoid mistakes by always being explicit.

current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

upstream - push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e. central workflow).

simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one.

So you can do below and set it to

git config --global push.default current

Dev-vruper
  • 392
  • 2
  • 10
1

In any case you have to push your new branch to the remote repo, but to make things shorter you can do following:

  • git push -u origin <new_branch> (instead of --set-upstream)
  • git push -u origin HEAD Pushing to HEAD is equivalent to pushing to a remote branch having the same name as your current branch
  • You also can create an alias for this commands, to do so check this out: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases
Monsieur Merso
  • 660
  • 1
  • 5
  • 12