user11680003
user11680003

Reputation:

why do I have to use --set-upstream when pushing a local branch

I acknowledge the fact that --set-upstream sets the default remote branch for the current local branch, which I can pull commits easier. But let's say I don't want to track a remote branch because I just create a branch for a quick fix, so I just need to push it and ask the team leader to review it and merge it. I don't need to use git pull to get latest commits because no other team member will work on my branch locally. In this case I don't need to use --set-upstream but I'm still forced to use this otherwise I can't push my branch.

Upvotes: 0

Views: 69

Answers (1)

torek
torek

Reputation: 488463

... In this case I don't need to use --set-upstream

Correct.

but I'm still forced to use this ...

No, you're not forced to use it. Use it if you want to, and don't use it if you don't want to.

If no upstream is set for the current branch and your push.default setting is simple,1 you will have to spell out all the details:

git push origin somebranch

or if you prefer:

git push origin HEAD

because the simple setting requires that the current branch have an upstream when you omit the refspec argument (the somebranch or HEAD part of the above two commands). Without an upstream, simple refuses to do the git push—but supplying a refspec overrides simple.


1The details here are somewhat version-dependent, as the default setting for push.default is different in Git 2.x vs Git 1.x. If you have set your push.default explicitly to simple, though, even ancient Git versions should behave like Git 2.0 or newer.

Upvotes: 1

Related Questions