Skip to content

Instantly share code, notes, and snippets.

@Fusselwurm
Last active February 28, 2019 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fusselwurm/2f553439f4fdc861d8c047f2d29c618a to your computer and use it in GitHub Desktop.
Save Fusselwurm/2f553439f4fdc861d8c047f2d29c618a to your computer and use it in GitHub Desktop.
rebase loop for projects with high push frequency and rebase-always policy
#!/bin/bash
projectdir=$(realpath $1)
frequency=$2
if [[ $frequency == "" ]]; then $frequency=30; fi
if [[ ! -d $projectdir ]]; then echo "first param must be a directory"; exit 2; fi
if [[ ! -d $projectdir/.git ]]; then echo "not a git project"; exit 4; fi
pushd $projectdir
branchname=$(git status -buno --porcelain | sed 's/## //');
if [[ $branchname == "master" ]]; then
echo "must not force-push master!"
popd
exit 1
fi
while [[ true ]]; do
git fetch
$diff=$(git diff origin/$branchname)
if [[ $? != 0]]; then
echo "error comparing to remote!"
popd
exit 8
fi
if [[ $diff != "" ]]; then
git rebase origin/master
git push -f origin $branchname
fi
sleep $frequency
done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment