Created
October 13, 2020 22:52
-
-
Save oshai/879fa744f6cc442972b3963ccb093a96 to your computer and use it in GitHub Desktop.
2-way-sync
This file contains 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 | |
set -e | |
echo 'commit all uncommited files' | |
ssh $P "cd $PROD_DIR; git add --all . ; git diff-index --quiet HEAD || git commit -m \"chore: periodic jenkins commit\"" | |
echo 'check for additional changes' | |
ssh $P "cd $PROD_DIR; git diff --exit-code || 'git ls-files --other --directory --exclude-standard | sed q1'" | |
cd $I_WORK_DIR | |
echo "pull from $P" | |
git pull --rebase origin master:master | |
echo 'pull from $G' | |
git pull --rebase g master | |
echo 'push to $G' | |
git push g master | |
echo "push to $P upload branch" | |
git push origin master:upload | |
echo "rebase master from upload on $P" | |
ssh $P "cd $PROD_DIR; git pull --rebase . upload" | |
echo "pull from $P last time to make sure it worked" | |
git pull --rebase origin master:master | |
## initial setup | |
# on P: | |
# git init | |
# prepare .gitignore | |
# git commit all files | |
# on I: | |
# git clone ssh://$P:$PROD_DIR dest | |
# cd dest | |
# git push -u origin master:upload (this creates an upload branch) | |
# git remote add g ssh://$G:$GIT_DIR (or use another sync alternative) | |
# git push g master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
part of the blog post: https://medium.com/@OhadShai/2-way-sync-with-git-2b48d1663e28