Created
February 6, 2019 19:04
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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