0

I have started working with Git recently. Normally I use eclipse Egit and very rarely git shell. After going through a lot of material on Git and its branching, I still have confusion regarding that.

I know there are n number questions on Stack Overflow on the same topic but so far I have only either added to my confusion or I have got half baked knowledge on branching. So I am putting the n + 1st question on this regarding my understanding.

Can somebody confirm if my understanding is correct:

  1. There are two types of branches: Local and Remote where local branches are branches on local repositories and Remote branches are on Remote Repositories
  2. There is third type of branch called Remote Tracking branch which automatically adjusts its head to match with the branch its tracking whenever we fetch the changes from remote branch.
  3. So a branch can only track some remote branch and not any local branch. Is this correct?
  4. When I clone a remote repository two types of branches are created automatically as follows:
    1. Local branch called as master.
    2. A Local Remote tracking branch which tracks the remote repository's master branch.
  5. Can my local master branch (mentioned in 4.1 above) track Remote tracking branch created on local (mentioned in 4.2)?
  6. If yes I guess it is automatically set to track this branch and thats why I don't have to do anything special to fetch /push the changes to remote repository from my working directory right? So when I fetch the changes using Eclipse's Team synchronizing following things happen
    1. Changes in Remote Branch come in Local Remote tracking branch (4.2)
    2. As my local master branch (4.1) is set to track Remote tracking brnach (4.2),they come in my local master branch (4.1).
    3. And from my master branch they come in working directory right?
  7. and the same happens in reverse when i try to push the changes Correct?
Shailesh Vaishampayan
  • 1,766
  • 5
  • 24
  • 52
  • Please make your question readable. Don't indent by 4. Hint: SO has numbered and bulleted lists, when you start your lines with a number `1. ` or a `*`. You are wrong about remote tracking branches, but it's extremely difficult to read your question, so I'll be waiting for your edit. – SzG Mar 11 '14 at 14:59
  • @SzG: Cupcake edited my question to resolve formatting issues. Was it not readable due to formatting issues? or due to phrasing of question? Sorry for the formatting errors. For the phrasing , i have made it amply clear or at least as clear as possible for me. What i expect in the answer is confirmation for each of the points and if there is something I am missing an explaination about waht I am missing. Please let me know you need more information – Shailesh Vaishampayan Mar 12 '14 at 04:21
  • Now it's much better. I'll be back with an answer soon. – SzG Mar 12 '14 at 07:15

2 Answers2

0
  1. True
  2. False. Remote Tracking Branches are just local branches. They definitely do not adjust themselves when you fetch from the remote repo. Ever.
  3. True
  4. True
  5. No. There is no such thing as a local master and a separate remote tracking local master. There can be only one local master.
  6. Does not make any sense
  7. Does not make any sense

The remote-tracking-ness of a local branch affects only the pull and push operations. But not fetch. It allows you to omit a few arguments when you type these commands.

For instance the local master is remote-tracking origin/master. To pull in the new commits from origin/master into the local master, you have to make sure your local master is checked out and then:

git pull origin master

But as master is remote-tracking origin/master, it's enough to say:

git pull

So remote-tracking is mostly syntactic sugar.

SzG
  • 12,333
  • 4
  • 28
  • 41
  • I agree with all your answers except 2,6,7. – Shailesh Vaishampayan Mar 12 '14 at 08:05
  • :I agree with all your answers except 2,6,7. For 2 i have read in several blogs that when you fetch from remote repository,"remote tracking local branch" is updated to point to latest commit that wasa fetched. (Obviously if Fetch refspecis configured properly.) please refer following link which I found today and is the better resource so far.[link]http://www.gitguys.com/topics/tracking-branches-and-remote-tracking-branches/[link] ..especially the fetch section in the page – Shailesh Vaishampayan Mar 12 '14 at 08:13
  • For 6 and 7 can you please explain how my working directory in eclipse project is updated when I synchronize it with git repo. Does it in the background fires several commands to fetch the changes from remote and then merge it with my local branch which in turn gets synchronized with workspace/working directory of Eclipse? – Shailesh Vaishampayan Mar 12 '14 at 08:17
  • I've never used git with Eclipse. Your gitguys link is broken. And if you disagree with 2,6,7, then you definitely know the answers. Why are you asking? – SzG Mar 12 '14 at 16:41
  • yes I know the answers , but I am not sure and I am confused. so I need th confirmation whether my answers ar ecorrect or if there is something missing. please try the following link . by mistake I added "[link']"at the end as well [link]http://www.gitguys.com/topics/tracking-branches-and-remote-tracking-branches/ I have tested the link now after posting the comment. Please confirm at least point no 2 – Shailesh Vaishampayan Mar 13 '14 at 06:08
0

(For future readers)

I agree with the assumptions of the author of the question from 1 to 4. However (5) master can not track origin/master when fetch.

When fetch (6), only origin/master is updated, so it is tracking the remote branch (6.1. is true).

However, for the local master and the working dire you have to merge or rebase (even better the second one) (6.2 and 6.3. are false).

Same way, for push, you push your master in origin (name of remote repository). Your local repo is when the changes of your working dir have been commited, so your working dir is not automatically pushed, is your local repo.

marilia15
  • 11
  • 2