This guide will discuss:
- Why do I require to “–set-upstream” all the time?
- How to Build Tracking Connection Using the “–set-upstream” Option?
So, let’s start!
Why Do I Require to Do “–set-upstream” All the Time?
To build a tracking connection between the remote and local repositories, you need to “–set-upstream” for the first time while pushing the local branch to the Git remote branch.
How to Build Tracking Connection Using the “–set-upstream” Option?
To set a tracking connection, firstly, navigate to the Git directory where the desired repository is located. Then, create and switch to the branch immediately. Clone Git remote repository and push the current branch to it. Lastly, run the “$ git push –set-upstream origin <local-branch>” command to set a tracking connection between local and remote branches.
Let’s implement the above-provided procedure for better understanding!
Step 1: Move to Directory
First, navigate to the Git local repository using the following command:
Step 2: Create and Switch Branch
Run the “git checkout” command with the “-b” option to create and switch Git local branch simultaneously:
Step 3: Clone Remote Repository
To clone Git remote repository, run the “git clone” command along with the remote URL:
Step 4: Git Push
Push the current Git local branch by utilizing the “git push” command:
Without setting the upstream, you will encounter the following error:
Step 5: Set Upstream Branch
To set an upstream local branch while performing a push operation from the local to the remote repository for the first time, run the “git push” command with the “–set-upstream” option:
The below-given output indicates that the local branch is set as an upstream branch:
We have offered the method to set the local branch as an upstream branch while pushing into the remote repository.
Conclusion
To set a tracking connection between local and remote repositories, firstly, move to the Git local repository. Then, create and switch to the branch immediately. Clone Git remote repository and push the current branch to it. Lastly, run the “$ git push –set-upstream origin <local-branch>” command on the bash terminal. This guide explained why we must “–set-upstream” all the time.