Skip to content

Instantly share code, notes, and snippets.

@oshai
Created October 13, 2020 22:52
Show Gist options
  • Save oshai/879fa744f6cc442972b3963ccb093a96 to your computer and use it in GitHub Desktop.
Save oshai/879fa744f6cc442972b3963ccb093a96 to your computer and use it in GitHub Desktop.
2-way-sync
#!/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
@oshai
Copy link
Author

oshai commented Oct 13, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment