Ability to edit local copies of remote branches

I have difficulty understanding/verifying the following line from Pro Git:

It’s important to note that when you do a fetch that brings down new
remote-tracking branches, you don’t automatically have local, editable
copies of them. In other words, in this case, you don’t have a new
serverfix branch — you have only an origin/serverfix pointer that you
can’t modify.

I tried the following for a repository.

git clone git://git.bugseng.com/ppl/ppl.git
cd ppl

I removed folder ppl/src/ from my local machine, and made a copy of pre-existing folder ppl/m4/ into ppl/m4 - Copy just so as to locally modify/edit this folder a bit.

Then, I ran git fetch origin just to (I thought) set myself up to be in the situation mentioned in the book’s quote above. I (of course) do not have any write access to this online repository.

Now, I am easily able to do git add . and git commit without any errors. Output of git status is:

:~/ppl$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.

all as expected. That is, I have been able to make a commit and edit the branch locally. I am unable to reconcile this with the quote from the book which states that I would not have local editable copies of them.

>Solution :

Notice that the phrases you quoted refer to a serverfix branch — not to master.

In the case of master (or whatever the remote HEAD is), when you clone you are given a local copy automatically; thus there was no need for you to make one.

But if there had been any other branches, clone does not make local copies of those for you, and a mere fetch would not have given you local copies of them either. You might have remote-tracking branches such as origin/someBranch, but if you wanted to edit someBranch, you’d have to create it first.

Leave a Reply