I would like to create a git alias that clones all branches.
We have the bash script, thanks to this post: How to clone all remote branches in Git?
Here is the bash script (multi-line version):
#!/bin/bash
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
done
(one line version):
git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs
Let's call the git alias git cloneallbranches
I have tried setting both one-line and multi-line versions using:
$ git config --global alias.cloneallbranches '...'
and tried to paste both versions into my .gitconfig file unsuccessfully (I have other git aliases, but none are bash scripts).
Can someone help me alter a bash script, so that I can paste it into my .gitconfig file, to make the git alias works properly?
Thank you.
ANSWER:
Running a separate bash script as a "git alias" answer in reply below.
However, for those who want a quick way to add a git alias, $ git clone-all-branches
here is an answer:
- Thanks to updated answer here: How to clone all remote branches in Git?
Create a "git alias" which will run a script:
$ git config --global alias.clone-all-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'
Now you can run (from any directory that has a git repo):
$ git clone-all-branches