Reputation: 89
I am learning git and it is getting confusing for me. I am confused about branches, remote repository and directories. Someone else cloned a code on my local machine. When I do git branch
I see these three branches:
ChrisMerge
* EliasWork
develop
and when I do git remote
I get these
chris
origin
prime
I thought maybe they are directories but I cannot find any directory named chris, develop. So where are the codes stored? Because the codes in each of them are different.
On my git account on github.com, I thought maybe I can see one of these names there. But under branches there are other names like, devel, ver, ...
I need someone to make this clear for me once and for all.
Upvotes: 0
Views: 424
Reputation: 89
Because I did not know even very basic things I could not ask the right questions. I tried to read and read and to understand git a little bit. I want to share the basic things that I did not know and hopefully it helps people who are not majored in computer science like me to understand git. Note that I am not trying to be accurate here, I just want you to get started like I did. You can see this awesome tutorial for more information.
Upvotes: 0
Reputation: 489748
A Git remote is just a short name under which Git stores some data. It's not a directory. Running git remote
lists all the remote names that Git knows about, which is basically everything that git config --list
will list that starts with remote.
: you will see:
remote.chris.url = <some url>
remote.origin.url = <another url>
remote.prime.url = <yet another url>
and probably additional lines such as:
remote.chris.fetch = +refs/heads/*:refs/remotes/chris/*
and so on. It's these lines' existence that creates the so-called remote. The fetch
lines in particular tell git fetch
what your Git should copy from some other Git, and the url
lines tell your Git how to contact each of the other Gits.
A branch name, by contrast, is a name that your Git uses to store one specific commit hash ID. This name is up to you—it's not controlled by any other Git, it's controlled by you when you ask your Git to create branch names. In general, if your remote named origin
has a branch named master
, your Git will remember that name as origin/master
and you might want your branch name master
to remember origin/master
which is your Git's way of remembering the master
on the Git that your Git calls up via remote.origin.url
.
Git calls these names—origin/master
and so on—remote-tracking names or remote-tracking branch names. They are not actually branch names, and they are different from (but obviously related to) the remotes. They're used for your Git to remember ("track") the branches on the remote, which is why they are called remote-tracking names.
Normally, none of this is particularly confusing, because most users in their Git repositories have only one remote, named origin
, so their master
will go along with origin/master
. But in your case, you have three remotes. The Git at the URL named via prime
probably also has a master
, which your Git will remember via prime/master
. So now you have both origin/master
and prime/master
. If you want to work with these, the usual recommendation would be to use your branch named master
to work with origin/master
, and to use your branch named master
to work with prime/master
. But this is doomed to failure—so you'll need to use some other local branch name(s), and that's where things get confusing.
Fortunately, as we just saw, your own branch names don't have to match some remote's name. You can have a branch like EliasWork
that is, or is not, connected to any of your remote-tracking names. The limitation is that each branch name can only have one of these set. Git calls this the upstream of the branch.
Extra-confusingly, when we set a remote-tracking name as the upstream of a branch, Git says that this branch is now "tracking" that remote-tracking name. So now we have:
Note that this keeps re-using various words, and having them mean different things! As terminology goes, it leaves a lot to be desired.
In any case, none of these are directories that you will see in your work-tree, which is where you do your work. (Git will sometimes create some directories within .git
using these names, but the .git
directory, which stores the repository itself, is not technically included in your work-tree.)
Upvotes: 2