What is the concept of upstream branch in Git?
漂亮男人
漂亮男人 2017-06-26 10:49:32
0
3
2455

The book "Pro git" mentions the concept of upstream branches when introducing branches.

Checking out a local branch from a remote tracking branch will automatically create a branch called a "tracking branch" (sometimes also called an "upstream branch")

From here, we can see that the upstream branch mentioned here refers to a local branch checked out from a remote branch.

However, when the "upstream shortcut" is mentioned later in this book, this upstream branch does not refer to the local branch:

After setting up the tracking branch, you can reference it through the @{upstream} or @{u} shortcut. So when you're on the master branch and it's tracking origin/master, you can use git merge @{u} instead of git merge origin/master

if you like

When we use git and push to a remote warehouse, we often encounter the concept of upstream branches. For example, when you push to the remote for the first time, you do not add any parameters:

git push

Then git will immediately prompt you to set up the upstream branch:

fatal: The current branch master has no corresponding upstream branch.

To push the current branch and establish tracking with the remote upstream, use

git push --set-upstream origin master

The upstream branch here seems to also refer to the remote branch.

So the question arises, what exactly is called an "upstream branch"? The book "Pro git" does not give an accurate concept; and it is also said on the Internet that the upstream branch is only a relative concept.

漂亮男人
漂亮男人

reply all(3)
仅有的幸福

Simply speaking, upstream is the remote branch corresponding to your local branch. If you do not specify the remote branch when pushing pull or fetch, the upstream branch will be used.

typecho

Hello, first of all, I have not read any Git books, but I dare say that I am very proficient in Git operations, which I have learned through long-term practice. Maybe I can understand your confusion!
First of all, the brain cannot stay on the previous SVN, which is the concept of a central warehouse! First of all, there is no central repository in Git, so the question arises, which part of your local code should be submitted to the remote one?
git branch --set-upstream branch This branch is the remote branch. Set an existing branch to track the remote branch. After you set up the remote tracking branch, you can type the command normally and simply: git pull; git psuh;
For example, when you push the remote for the first time, you did not add any parameters:
git push
Then git You will be prompted immediately to set up the upstream branch:
Then you need to git push origin master; by default, the current remote branch is the main branch

代言

According to the usual usage, the upstream branch refers to a branch of the remote library. This library can be an account in github, or it can be a directory on a certain server (including local). set-upstream is to The current branch is connected to branches in other libraries, so that a set of code can be modified together instead of just doing it yourself

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template