-
-
Save wilmarvh/95fe7daed6ee6a63d811677e040ae421 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
#Whenever you clone a repo, you do not clone all of its branches by default. | |
#If you wish to do so, use the following script: | |
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master | grep -v main `; do | |
git branch --track ${branch#remotes/origin/} $branch | |
done |
Awesome!! Thanks a lot
You made my day. Thanks a lot!!!
Nice little script! After using it myself, I encountered a neat little git command which does all of this for you during the git clone step.
You can use git clone --mirror REPO_URL
to clone all branches instantly.
Nice little script! After using it myself, I encountered a neat little git command which does all of this for you during the git clone step. You can use
git clone --mirror REPO_URL
to clone all branches instantly.
It works like a charm! Thanks a lot!
it`s look like good. I will try it 🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙🤙
You probably want to add grep -v main
as well.
You probably want to add
grep -v main
as well.
Added, thanks!
Here is a slightly more verbose version that fixes some issues with the original...
- fetches refs so branches that exist on the remote but not locally are tracked
- works no matter what your default branch is named (i.e. not just main/master)
- works even if you have git configured to display branches in color
- won't display an error if branch already exists locally
git fetch
default_branch=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
for remote_branch in $(git branch --all --no-color | grep remotes | grep -v "${default_branch}"); do
branch="${remote_branch#remotes/origin/}"
git branch --track "${branch}" "${remote_branch}" 2>&1 | grep -v "already exists"
done
Nice!! Works like a charm!