Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git checkout all remote branches
#!/bin/bash
remote=origin ; for brname in `git branch -r | grep $remote | grep -v /master | grep -v /HEAD | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do git branch --track $brname $remote/$brname || true; done 2>/dev/null
@kublermdk
Copy link

kublermdk commented Apr 6, 2021

This is exactly what I wanted. Thank you.

I've added that to my bash aliases file as a function.

function gitCheckoutAllBranches {
        remote=origin;
        for brname in `git branch -r | grep $remote | grep -v /master | grep -v /HEAD | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`;
                do git branch --track $brname $remote/$brname || true;
        done
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment