Last active
August 29, 2015 14:10
-
-
Save soutar/ff701834d0ce6194f677 to your computer and use it in GitHub Desktop.
Pull all repos in the current directory
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
| #!/bin/bash | |
| stash_name="wip" | |
| echo "> Updating master on all git repositories in the current directory" | |
| for dir in */ | |
| do | |
| if [ -d ${dir}/.git ]; then | |
| cd ${dir} | |
| stashed=false | |
| echo "----------------------------------------------------" | |
| echo "- Processing ${dir}" | |
| echo "----------------------------------------------------" | |
| current_branch=$(git symbolic-ref --short HEAD) | |
| # If git status has any output then we need to stash our changes | |
| # so we can restore them after | |
| if [[ -n $(git status -s) ]]; then | |
| echo "> Saving WIP changes" | |
| git stash save ${stash_name} | |
| stashed=true | |
| fi | |
| # If we're not on master, checkout master | |
| if [[ ${current_branch} -ne "master" ]]; then | |
| echo "> Checking out master" | |
| git checkout master | |
| fi | |
| echo "> Pulling master" | |
| git pull origin master | |
| # If we've moved branch, checkout the branch we started on | |
| if [[ $(git symbolic-ref --short HEAD) -ne ${current_branch} ]]; then | |
| git checkout ${current_branch} | |
| fi | |
| # If we stashed changes previously, restore them | |
| if [[ ${stashed} = true ]]; then | |
| echo "> Restoring WIP changes" | |
| git stash pop stash^{/${stash_name}} | |
| fi | |
| cd - > /dev/null # Leave the repo | |
| fi | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm ok with stashing if it's automatically put back on, but still wary here. The other thing is as mentioned all the various combos of, is the index dirty, is the repo on master (obviously it shouldnt really be dirty on master, but we all do that sometimes by mistake and then create a branch later). If its on another branch should it update that branch or should it update master? (this could be a parameter to pass ๐ ). These aren't problems or anything preventing from working, just things to take into account and features to add i guess ๐