Upstream and Downstream

  • Post author:
  • Post category:Git
  • Post comments:1 Comment
Upstream and Downstream

The term upstream and downstream refers to the repository. Generally, upstream is from where you clone the repository, and downstream is any project that integrates your work with other works. However, these terms are not restricted to Git repositories.

There are two different contexts in Git for upstream/downstream, which are remotes and time/history. In reference to remote upstream/downstream, the downstream repo will be pulled from the upstream repository. Data will flow downstream naturally.

In reference to time/history, it can be unclear, because upstream in time means downstream in history, and vice-versa. So it is better if we use the parent/child terms in place of upstream/downstream in case of time/history.

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.

Sometimes we are trying to push some changes to the remote server, but it will show the error like “error: failed to push some refs to ‘HTTPS :< remote repository Address>.” There may be a reason that you have not set your remote branch. We can set the remote branch for the local branch. We will implement the following process to set the remote server:

To check the remote server, use the below command:

$ git remote -v  

It will result as follows:

Upstream and Downstream

The above output is displaying the remote server name. To better understand remote servers, check the available branches, run the below command:

$ git branch -a  

It will result as follows:

Upstream and Downstream

The above command will list the branches on the local and remote repository. To learn more about branches, Now push the changes to the remote server and set the particular branch as the default remote branch for the local repository. To push the changes and set the remote branch as default, run the below command:

$ git push --set-upstream origin master  

The above command will set the master branch as the default remote branch. To better understand the origin master.

Consider the below output:

Upstream and Downstream

In the given output, everything is up to date with the remote branch.

We can also set the default remote branch by using the git branch command. To do so, run the below command:

$ git branch --set-upstream-to origin master  

To display default remote branches, run the below command:

$ git branch -vv  

Consider the below output:

Upstream and Downstream

The above output is displaying the branches available on the repository. We can see that the default remote branch is specified by highlighted letters.

Next Topic: Click Here

This Post Has One Comment

Leave a Reply