Skip to content

Instantly share code, notes, and snippets.

@siredmar
Last active July 24, 2020 07:34
Show Gist options
  • Save siredmar/d07987d92c1242da36b448f4ea082b26 to your computer and use it in GitHub Desktop.
Save siredmar/d07987d92c1242da36b448f4ea082b26 to your computer and use it in GitHub Desktop.
Script that fetches and pulls all remote branches of a bunch of git repositories
#!/bin/bash
#usage: ./fetchall.sh <dir-containing-several-git-repos>
input=$1
for git in $(find $input -maxdepth 1 -mindepth 1 -type d -printf '%f\n')
do
git -C $input/$git branch -r | grep -v '\->' | while read remote; do git -C $input/$git branch --track "${remote#origin/}" "$remote"; done
git -C $input/$git fetch --all
git -C $input/$git pull --all
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment