EN
Git / Bash - clone repository with all branches
9 points
In this short article, we would like to show how to clone Git repository with all its branches.
Quick solution:
xxxxxxxxxx
1
git clone https://domain.com/path/to/repository.git
2
3
cd "!$:t:r" && git branch -a | sed -n '/\/HEAD /d; /remotes/p;' | xargs -L1 git checkout -t
4
5
6
# optionally you can later run commands:
7
8
git fetch --all
9
git pull --all
Where:
cd "!$:t:r"
navigates to repository directory achieved fromhttps://domain.com/path/to/repository.git
- Where:
!$
returns last argument from previous command,:t
returns tailing part from the path (repository.git
in our case),:r
returns only basename from the filename (repository
in our case),
- Where:
sed -n '/\/HEAD /d; /remotes/p;'
prints only lines withremotes
word, omitting lines with/HEAD
word,xargs -L1 git checkout -t
takes input lines as arguments and calls for each linegit checkout -t
command.