Skip to content

Instantly share code, notes, and snippets.

@hazcod
Created October 13, 2016 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hazcod/b73c4f3c104447af9893eb58c132551a to your computer and use it in GitHub Desktop.
Save hazcod/b73c4f3c104447af9893eb58c132551a to your computer and use it in GitHub Desktop.
Pull changes from remote to a bare git repo.
#!/usr/bin/env bash
#set -e
#set -x
# directory where your git repos reside
repo_dir="/home/hazcod/repos/"
# the repos in repo_dir that should be pulled from remote (origin)
repos=(myproject)
for repo in ${repos[@]}; do
echo "-- ${repo}"
cd "${repo_dir}${repo}.git"
echo ">>> Fetching all remotes ..."
if ! git fetch --all; then
echo "ERROR: Failed fetching. Exiting.."
exit 1
fi
echo ">>> Tracking all branches ..."
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote" 2>/dev/null; done
echo ">>> Pruning old refs ..."
git remote prune origin
echo ">>> Fetching all branches ..."
git branch -r | grep -v '\->' | while read remote; do git fetch origin "${remote#origin/}:${remote#origin/}"; done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment