Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push --set-upstream vs --set-upstream-to

Tags:

git

push

according to this article, git push --set-upstream is deprecated and git push --set-upstream-to should be used instead.

But when I checked the git push documentation, I can only find --set-upstream, but --set-upstream-to is no where to be found.

So is --set-upstream deprecated? Should I use --set-upstream or --set-upstream-to?

like image 496
Thor Avatar asked Aug 09 '17 02:08

Thor


People also ask

What is git push -- set upstream?

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.

Does git push push to origin or upstream?

By default, Git chooses origin for the remote and your current branch as the branch to push. If your current branch is main , the command git push will supply the two default parameters—effectively running git push origin main .

What is git branch -- set upstream?

With an upstream branch set, you can simply use the shorthand commands "git pull" and "git push" - instead of having to think about the exact parameters like in "git push origin development". Git can now also tell you about unsynced commits which you haven't pushed or pulled, yet.

What is upstream in git?

In the git world, upstream refers to the original repo or a branch. For example, when you clone from Github, the remote Github repo is upstream for the cloned local copy.


1 Answers

This mixes up git branch and git push.

The git branch command has both --set-upstream and --set-upstream-to, with the former deprecated in favor of the latter for the reason already given in Nick's answer.

The git push command has only -u aka --set-upstream, which takes no argument. It means that if the push succeeds, your local Git should set, as the upstream of a branch reference supplied as your source, the remote-tracking branch corresponding to the destination branch you got the other Git to set, which in many cases, your own Git has just now created in your repository because their Git has also just created their branch. (Whew!)

That is, suppose you have created a branch newbranch:

$ git checkout -b newbranch
... work, commit, etc

and want to set its upstream to origin/newbranch. But if you try, it fails:

$ git branch --set-upstream-to=origin/newbranch
error: the requested upstream branch 'origin/newbranch' does not exist

because origin/newbranch does not exist yet, because the other git at origin does not have a branch named newbranch.

Soon, however, you git push your local newbranch to their Git, so that their Git creates newbranch in their repository. Now that they do have a newbranch, your Git creates your origin/newbranch to remember their newbranch. And now you can use git branch --set-upstream-to, but it might be nice if git push could do that automatically—and that's the git push --set-upstream, aka -u, option.

It's related to git branch --set-upstream-to, but not the same.

like image 76
torek Avatar answered Oct 17 '22 18:10

torek