Created
August 19, 2021 10:36
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script requires the GitHub CLI.