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:
git clone https://domain.com/path/to/repository.git
cd "!$:t:r" && git branch -a | sed -n '/\/HEAD /d; /remotes/p;' | xargs -L1 git checkout -t
# optionally you can later run commands:
git fetch --all
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,:treturns tailing part from the path (repository.gitin our case),:rreturns only basename from the filename (repositoryin our case),
- Where:
sed -n '/\/HEAD /d; /remotes/p;'prints only lines withremotesword, omitting lines with/HEADword,xargs -L1 git checkout -ttakes input lines as arguments and calls for each linegit checkout -tcommand.