Skip to content

Instantly share code, notes, and snippets.

@bashkirtsevich
Created July 27, 2019 07:40
Show Gist options
  • Save bashkirtsevich/b31ca6a3ae7a5a323b671dc4ef0572eb to your computer and use it in GitHub Desktop.
Save bashkirtsevich/b31ca6a3ae7a5a323b671dc4ef0572eb to your computer and use it in GitHub Desktop.
Git dumper
// Public repository
./gitdump.sh <repo_name>

// Your repository (public AND private)
./gitdump.sh <your_username> user

// Organization repository (public AND private)
./gitdump.sh <your_username> orgs <your_organization_name>
# Args.
username=$1
type=$2
orgs=$3
# Today's date
today="$(date +'%Y%m%d')"
# Call the Github API.
if [ "$type" = "orgs" ]
then
api=$(curl -s -u $username https://api.github.com/orgs/$orgs/repos?per_page=1000 | jq -r '.[] | .name + "|" + .clone_url + "|" + .updated_at')
elif [ "$type" = "user" ]
then
api=$(curl -s -u $username https://api.github.com/user/repos?per_page=1000 | jq -r '.[] | .name + "|" + .clone_url + "|" + .updated_at')
else
api=$(curl -s https://api.github.com/users/$username/repos | jq -r '.[] | .name + "|" + .clone_url + "|" + .updated_at')
fi
# Loop over the URLs and clone the repositories.
for i in $(echo $api | tr " " "\n")
do
name=$(echo $i | cut -d"|" -f1)
clone_url=$(echo $i | cut -d"|" -f2)
git clone $clone_url ./$name && tar -czvf ./$name.tar.gz -C ./$name .
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment