Skip to content

Instantly share code, notes, and snippets.

@bartimaeus
Created February 6, 2019 19: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 bartimaeus/b630ab175132fa0c233f6355a8e535b0 to your computer and use it in GitHub Desktop.
Save bartimaeus/b630ab175132fa0c233f6355a8e535b0 to your computer and use it in GitHub Desktop.
Bash function to sync git repository. I use this when automatically pulling changes from many repositories so that I don't have to open each repo and determine if it's dirty or clean.
# Determine if we need to stash or not when updating git repository
function git-sync {
untracked=$(expr `git status --procelain 2>/dev/null | grep "^??" | wc -l`)
if [ "$untracked" = "0" ]; then
git pull --rebase
else
git stash
git pull --rebase
git stash apply
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment