Git

Checkout a branch name in all directories

We have a bunch of different repos that all have develop as their main branch. Sometimes I am working in various feature branches and then want to check out develop in all of them.

Here’s a concise one-liner to switch to the develop branch for each folder under your current working directory:

for dir in */; do [ -d "$dir/.git" ] && (cd "$dir" && git checkout develop); done

This one does a git pull as well:

for dir in */; do [ -d "$dir/.git" ] && (cd "$dir" && git checkout develop && git pull); done