You need to understand What Is Git Upstream and How to Set Upstream Branch? and how to set them up before you can clone a Git repository or add new features using branches.
This article provides a general overview of What Is Git Upstream is and How to Set the Upstream Branch? as well as how to see which Git branches are tracking which upstream branches.
- Installed and set up Git
- a locally built-up Git project or a cloned Git repository
What is a Git Upstream Branch?
Upstream is delivering your data back to where the river stream is coming from, using a river analogy to describe the flow of data. Sending anything upstream means returning it to the repository’s founding authors.
You can decide where your current local branch will flow by using git set upstream. You are able to modify the remote branch’s default setting.
How to Set Upstream Branch in Git?
What Is Git Upstream and How to Set Upstream Branch? In Git, there are two methods for creating an upstream branch:
- The quickest way to create a single upstream branch is to use git push.
- By means of a brief alias command. If you frequently alter the flow of your current branch, then this approach makes sense.
Method 1: Setting Upstream Branch Using Git Push
The simplest method for creating upstream branches in Git is to use git push.
1: Establish a new branch and name it. Ours is called a test. Use the checkout command’s -b option to switch to it:
branch name> git checkout
An indication of the switch branch appears:
2: Create an upstream branch by using the longer —set-upstream command or the git push command with the -u extension. Change branch name> to the name of your branch.
branch name> git push -u origin
Alternatively:
—set-upstream origin git push branch name>
Your branch is verified as having been set up to track a remote branch:
There is an established upstream branch for the test branch.
Method 2: Set Upstream Branch Using Alias
Establish a quick alias command instead of repeating these steps each time you create a new branch. You can write a bash command or alter your current Git commands.
1: Use the —global command in git config to configure the global alias command:
—global alias. Alias name> in git configuration "pushing -u origin HEAD"
What Is Git Upstream and How to Set Upstream Branch? Alternately, use alias to build a bash alias command:
Alias 'git push -u origin HEAD' = 'alias name'
2: Type: to use your global alias.
git —aliases
Or by entering the name of your bash alias:
The alias name
How to Modify the Git Upstream Branch?
Run: to track an alternative upstream branch to the one you just created.
git branch -u "name of remote branch"
For instance:
origin/global> git branch
A confirmation message is printed out by the terminal:
How to Determine Which Git Branches Track Each Upstream Branch?
Use the -vv option of the git branch to display a list of all your branches and branch tracking:
branch -vv for git
A tracking branch named [origin/main] is present on the main branch. The tracking branch for the test branch is [origin/global]. The global branch has no upstream branch and no tracking branches.
Conclusion
What Is Git Upstream and How to Set Upstream Branch? should now be familiar to you, along with their purpose and, most importantly, how to create one in Git.
Experiment freely and become accustomed to upstream. A git branch can be quickly deleted both locally and remotely, as well as eliminated from a repository.