Last active
December 29, 2020 18:32
-
-
Save synsa/ea69e2d8e989bbd526225754fca333b0 to your computer and use it in GitHub Desktop.
git-sync bash script
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
#!/usr/bin/env bash | |
# Sync your project from anywhere | |
# Script powerful when paired with a cronjob to constantly | |
# pull in changes from upstream maintainer that may do constant commits. | |
# Such as in team environments | |
# HOW-TO: | |
# $ git-sync $HOME/code/projects/expressjs upstream/master | |
REPO=$1; | |
MAINTAINER=($(echo $2 | cut -d/ -f1)) | |
MAINTAINER_BRANCH=($(echo $2 | cut -d/ -f2)) | |
gitcmd() { | |
/usr/bin/git --git-dir=$REPO/.git --work-tree=$REPO $@ | |
}; | |
REQUIRED_BRANCH=`gitcmd rev-parse --abbrev-ref HEAD` | |
if [ "$REQUIRED_BRANCH" == 'master' ]; then | |
gitcmd pull -Xtheirs --no-edit --commit $MAINTAINER $MAINTAINER_BRANCH | |
else | |
PREV_BRANCH=`gitcmd rev-parse --abbrev-ref HEAD` | |
gitcmd checkout master | |
gitcmd pull --rebase -Xtheirs --no-edit --commit $MAINTAINER $MAINTAINER_BRANCH | |
gitcmd checkout $PREV_BRANCH | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment