Skip to content

Instantly share code, notes, and snippets.

@lrvick
Last active July 25, 2022 06:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrvick/f495e02f71603f396fb9 to your computer and use it in GitHub Desktop.
Save lrvick/f495e02f71603f396fb9 to your computer and use it in GitHub Desktop.
Locally sync all Github repos & branches for user/org
#!/bin/bash
USER='lrvick'
ACCESS_TOKEN='YOUR_TOKEN_HERE'
API="https://api.github.com/orgs"
ENDPOINT="/${USER}/repos?per_page=200&access_token=${ACCESS_TOKEN}"
FOLDER='/home/lrvick/Sources'
REPO_NAMES=$( curl -s "${API}${ENDPOINT}" | \
grep \"name\" | sed 's/ \"name\": \"\(.*\)\",/\1/g'
)
cd $FOLDER
for name in $REPO_NAMES; do
echo Syncing $USER/$name
if [ ! -d $name ]; then
git clone git@github.com:${USER}/${name}.git
fi
cd $FOLDER/$name
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`;do
git branch --track ${branch##*/} $branch
done
git fetch --all
git pull --all
cd $FOLDER
done
@sergeyklay
Copy link

sergeyklay commented Dec 23, 2020

I just created a small tool for the same purpose https://github.com/sergeyklay/gstore

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