Information Technology Reference
In-Depth Information
Open your .gitconfig file with a text editor and at the end of the [alias] section
type the aliases shown in Listing 5-1 . Remember that you have to remove all the
newline characters. Save the file and close the editor.
Listing 5-1. The aliases to clone a repository with branches
list-remote-branches = "!listRemoteBranches() {
git branch -r | sed \"/->/d; s/ origin\\///g\";
}; listRemoteBranches"
checkout-remote-branches = "!checkoutRemoteBranches() {
for name in `git list-remote-branches`; do
git checkout $name;
done;
}; checkoutRemoteBranches"
clone-with-branches = "!cloneWithBranches() {
git clone $1 $2;
cd $2;
git checkout-remote-branches;
git remote rm origin
}; cloneWithBranches"
You can verify that the alias works as expected by running the following command:
$ git clone-with-branches 05-01 05-03
How It Works
As you already know, you can list remote tracking branches with the command:
$ git branch -r
If you clone the repository 05-01 then the above command will print:
origin/HEAD -> origin/master
 
 
Search WWH ::




Custom Search