Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '--set-upstream' do?

What does git --set-upstream do?

I tried to understand it by reading the git manual, but I didn't quite get it.

like image 269
Евгений Масленков Avatar asked Aug 03 '13 10:08

Евгений Масленков


People also ask

What does set upstream do?

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.

What does it mean to set upstream branch?

When you set your upstream (or tracking) branches, you can simply execute pulls and pushes without having to specify the target branch. Git automatically knows that it has to fetch the new commits to the remote tracking branch. Similarly, Git already knows that it has to push new commits to the upstream branch.

What does upstream mean in git?

Upstream and downstream in Git are usually defined with the context of a repository. In general terms, upstream refers to the location through which we clone the repository. The term downstream is defined as the process of integrating our work with other works.

Why do we add upstream in git?

Setup Git Upstream For a Repository Let's say you are working on a forked project and you want to sync changes from the main project repo. You can add the actual repo as an upstream to your local copy. This way you can pull all the changes happening in the main project repo.


1 Answers

To avoid confusion,
recent versions of git deprecate this somewhat ambiguous --set-upstream option
in favor of a more verbose --set-upstream-to option
with identical syntax and behavior.
[ Reference ]


git branch --set-upstream-to <remote-branch> 

sets the default remote branch for the current local branch.

Any future git pull command (with the current local branch checked-out),
will attempt to bring in commits from the <remote-branch> into the current local branch.


One way to avoid having to explicitly type --set-upstream / --set-upstream-to is to use its shorthand flag -u as follows:

git push -u origin local-branch 

This sets the upstream association for any future push/pull attempts automatically.
For more details, checkout this detailed explanation about upstream branches and tracking.

like image 133
TheCodeArtist Avatar answered Oct 03 '22 05:10

TheCodeArtist