Skip to content

Instantly share code, notes, and snippets.

@vejandla
Last active January 6, 2022 16:26
Show Gist options
  • Save vejandla/9565fbdcc3ffdf94cdcc560c1e0ca393 to your computer and use it in GitHub Desktop.
Save vejandla/9565fbdcc3ffdf94cdcc560c1e0ca393 to your computer and use it in GitHub Desktop.
Checkout all branches locally

rip off from

(1) Inside git local repostitory, create a new sh file

touch getAllBranches.sh vi getAllBranches.sh

(2) Insert the below content to getAllBranches.sh file:

for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
   git branch --track ${branch#remotes/origin/} $branch
done

(3) Get all branches:

chmod +x getAllBranches.sh sh getAllBranches.sh

(4) Check result at local repository:

git branch

Open git bash in windows, navigate to repo and execute the following command.

for BRANCH in $(git branch -a | grep remotes | grep -v HEAD | grep -v main); do git branch --track "${BRANCH#remotes/origin/}" "${BRANCH}"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment