When a user connects the local repository to the GitHub repository for the first time, they need to set a default branch as a tracking branch. So, when they perform push, pull, or fetch operations, it is not required to mention the branch name separately every time. Once you set the default branch, you can use that branch to perform these operations smoothly.
This blog will illustrate:
What is Git Upstream?
The term “Git upstream” refers to the branch. It can be set while connecting the local repository with the remote repository for updating the remote server through the local branch. Git “–set-upstream” option allows users to set the default remote GitHub branch for their current local repository. When users perform different operations, such as fetch, pull, push, and many more, the configured branch as an upstream can be used.
How to Set the Git upstream?
To set the Git upstream, first, switch to the desired directory and check its remote. Then, execute the “git push –set-upstream <remote> <branch” or “git push -u <remote> <branch” command. To do so, follow the provided steps.
Step 1: Move to Local Repository
First, write out the below-listed command with the directory path and redirect to it:
Step 2: Verify Remote Origin
Then, check whether the local repository is linked to the remote repository or not:
It can be observed that the remote is added to the local repository:
Step 3: Set Git Upstream
Next, execute the following command with the “–set-upstream” option, remote, and branch name to set the tracking branch:
In the below-provided screenshot, it can be observed that the local “main” branch has been set up to the “origin/main” tracking branch:
Another way to set the upstream, utilize the “-u” option instead of using the full “–set-upstream” option:
That was all about Git upstream and the method to set the Git upstream.
Conclusion
The Git upstream is used while connecting the local repository with the remote repository for updating the GitHub repository through the local branch. To set the Git upstream, first, switch to the desired directory and verify its remote. Then, run the “git push –set-upstream <remote> <branch” or “git push -u <remote> <branch” command. This blog illustrated about Git upstream and its setup procedure.