Information Technology Reference
In-Depth Information
$ git branch -r | sed "/->/d; s/ origin\///g"
the output will contain only branch names:
doc
info
master
That's how we get the list of names of all remote tracking branches in the cloned re-
pository.
The second alias, $ git checkout-remote-branches , contains a for loop
that processes the names returned by the $ git list-remote-branches alias:
for name in `git list-remote-branches`; do
git checkout $name;
done;
For every name we execute the checkout command, it creates a local tracking
branch. When the loop is finished the newly created clone contains all the branches
from the original repository.
The last alias, $ git clone-with-branches , performs four operations:
• It clones the original repository: $ git clone $1 $2
• It enters the directory with a new clone: cd $2
• It creates local branches: $ git checkout-remote-branches
• Itremoves therelationship totheremote repository: $ git remote rm
origin
Notice, that Recipe 5-3 and Recipe 2-4 both produce similar results. The repositor-
ies created with the $ cp -R command or the $ git clone-with-branches
alias contain the same branches as the original repository and no remotes. The main
difference between these two procedures is that cloning clears reflog while copying
preserves it.
The concept of local tracking branches and remote tracking branches can be unclear
if you are new to git. We will discuss both local tracking branches and remote tracking
branches in greater detail, emphasizing their role once again in the chapter concerning
synchronization. Then, I hope, their purpose will become clearer.
Search WWH ::




Custom Search