No More Manual Pulling: How to Automatically Pull All Git Branches from Remote to Local

Posted by Chaitanya Shahare on Sat, May 13, 2023

Problem

When you clone a repo to your local machine, it doesn’t pull all the branches to your local. Then you have to manually pull the branches you want.

Solution

To pull all the branches from the remote, run the following command

git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

Done!

Resources