Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

git the meaning of term "remote branch"

I type

git checkout staging

and a local branch staging is created, and in command prompt, it said

Branch 'staging' set up to track remote branch 'staging' from 'origin'.

but I feel some ambiguous about the term remote branch 'staging' from 'origin'....in fact the so-called remote branch is also in my local repository, just it track the remote git server branch name 'staging'? then that branch should call "track remote branch 'staging' from 'origin', not my just checkouted branch?

in git, when said remote branch, it usually mean remote tracking branch in local repository, not the branch really reside in remote (another location) git server?

then how to call (how to describle) the branch really in remote (another location) git server?

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Git's own documentation and terminology usage is not entirely consistent here. It does, however, all make sense once you understand each of the pieces that Git is using.

First, there is the remote, which is a short name like origin.1 This name provides a couple of items, the most important of which is a URL. This URL lets your Git (your Git software operating on your Git repository) contact some other Git (the same or different version of the Git software, operating on some other Git repository).

Next, there are branch names like master or main and any other names you create. Each one of these names also provides a couple of items, the most important of which is to give you the hash ID of some particular commit. The commit hash ID found in a branch name is, by definition, the last commit in some chain of commits. Being "last" makes it your most recent, usually; Git calls this commit the tip commit of the branch.

Since your Git talks to some other Git, that other Git—the "remote Git", or whatever phrase you'd like to use—has its own branch names. When your Git calls up that Git, your Git can see their branch names. The logical term for the branch names on some remote is a remote branch. Sometimes, that's what people who say "remote branch" mean.

But after your Git gets in touch with that Git and brings over any of their commits they have that you don't yet (so now you have them), your Git will create, in your repository, some similar names. If they have a branch named main, and your Git calls their Git origin, your Git will create origin/main. If they have a branch named develop, your Git will create origin/develop.2

I call these origin/* style names remote-tracking names. Parts of Git call them remote-tracking branch names. Other parts of Git, and other people, sometimes call them remote branches.

Obviously, then, the term remote branches is ambiguous. Sometimes it means a branch name as seen on the remote, and sometimes it means a remote-tracking name as seen in your own repository. By using the phrase branch name as seen on the remote named _____ (fill in the blank), you can be clear about what you mean here, for instance.

It turns out the term branch is ambiguous, too: see What exactly do we mean by "branch"? I try to use the phrase branch name to be more specific whenever necessary.


1Since you control the name, you can use a really long name here. That would be counterproductive, so I'll just assume you use a short one. :-)

2This is really create or update, and you can instruct your Git not to bother with all of their branch names—but this is the default. Note that there's a minor flaw here by default: if they delete one of their branch names after your own Git has copied their name to your remote-tracking name, your Git won't delete your remote-tracking name. So over time, your Git will build up "stale" remote-tracking names.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...