Skip to content

Instantly share code, notes, and snippets.

@bmmalone
Created August 19, 2021 10:36
Show Gist options
  • Save bmmalone/41556b29240dc01ee47a6564f9b130b1 to your computer and use it in GitHub Desktop.
Save bmmalone/41556b29240dc01ee47a6564f9b130b1 to your computer and use it in GitHub Desktop.
Pull and update all github repositories and all branches for a given user
#! /usr/bin/env bash
set -vx
gh_token=/path/to/my/gh-token.txt
account=my_account
# login to github
gh auth login --with-token < "$gh_token"
# first, clone any repos which have been added
gh repo list "$account" | while read -r repo _; do gh repo clone "$repo" "$repo"; done
# find all git repos rooted below this directory
for repo in `find $(pwd -P) -name ".git" -type d`
do
# change into the main folder for the repo
cd "$repo"/..
# find all of the branch names
for b in `git branch -r | grep -v 'HEAD' | sed 's_origin/__'`
do
# checkout and pull/update that branch
git checkout $b
done
done
@bmmalone
Copy link
Author

This script requires the GitHub CLI.

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