Last active
August 29, 2015 13:58
-
-
Save ianlintner-wf/9956849 to your computer and use it in GitHub Desktop.
Poll the remote git repository using git fetch & then git status && pull from git hub based on the status of the branch.
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 | |
| #Current (Remote) Branch | |
| currentbranch="" | |
| #Fetch from the remote branch | |
| echo "polling..." | |
| if [ -n "$currentbranch" ]; then | |
| git fetch $currentbranch | |
| else | |
| git fetch | |
| fi | |
| #Poll the status of the repo | |
| status=$(git status -uno) | |
| #Regex to search the status message e.g. branch is behind | |
| regex="Your branch is behind" | |
| #Run the regex match | |
| if [[ $status =~ $regex ]] ; then | |
| echo "Your branch is behind.\nupdating..." | |
| #Pull from git repo | |
| if [ -n "$currentbranch" ]; then | |
| git pull $currentbranch | |
| else | |
| git pull | |
| fi | |
| #optional for use with submodules | |
| git submodule update --init | |
| #Insert code here to perform other functions following pull. | |
| else | |
| #Branch is up to date | |
| echo "Your branch is up to date." | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment