Skip to content

Instantly share code, notes, and snippets.

@Demonstrandum
Last active September 9, 2017 21:08
Show Gist options
  • Save Demonstrandum/fd5a75d7a47ab9facd7762dffbfd8094 to your computer and use it in GitHub Desktop.
Save Demonstrandum/fd5a75d7a47ab9facd7762dffbfd8094 to your computer and use it in GitHub Desktop.
Pull all your git repos to update them all
#!/bin/bash
ORIGIN=$(pwd)
REPOROOT="$1"
if [ -z "$1" ]; then
REPOROOT="$HOME/Git"
if ! [ -d "$REPOROOT" ]; then
REPOROOT="$HOME/git"
fi
if ! [ -d "$REPOROOT" ]; then
printf "%s\n" \
"No Git folder found!" \
"Please specify a path to your git repos," \
"e.g. \`pull-repos ~/MyGitRepos/\`"
exit 1
fi
fi
REPOS="$(ls -l $REPOROOT | awk '{print $9}')"
cd "$REPOROOT"
for REPO in $REPOS; do
cd "$REPO"
printf "\nPulling: \'$REPO\'\n"
if [ -d "./.git/" ]; then
git reset --hard HEAD
git pull
fi
cd "$REPOROOT"
done
cd "$ORIGIN"
echo "Done, all repos pulled in $REPOROOT"
@Demonstrandum
Copy link
Author

Demonstrandum commented Jun 21, 2017

$> git clone https://gist.github.com/fd5a75d7a47ab9facd7762dffbfd8094.git && cd fd5a*
$> chmod +x pull-repos.sh
$> sudo mv pull-repos.sh /usr/local/bin/pull-repos

$> pull-repos ~/Folder-holding-all-my-git-repos/ # Default is `~/Git*` or `~/git*`
HEAD is now at 12a3456 A commit.
From github.com:username/the-repo
etcetera...

$> # All your repos are up to date with their remotes

or run copy paste this in to a script and run it:
(vim temp.bash, copy, paste, then bash temp.bash)

#!/bin/bash

git clone https://gist.github.com/fd5a75d7a47ab9facd7762dffbfd8094.git ./puller
cd ./puller
chmod +x ./pull-repos.sh
sudo mv ./pull-repos.sh /usr/local/bin/pull-repos
cd ..
rm -rf ./puller

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