Skip to content

Instantly share code, notes, and snippets.

@kdave
Created September 4, 2024 00:17
Show Gist options
  • Save kdave/2c08c9202870ff90ce9e4610d59fd7c7 to your computer and use it in GitHub Desktop.
Save kdave/2c08c9202870ff90ce9e4610d59fd7c7 to your computer and use it in GitHub Desktop.
#!/bin/sh -x
#
remote=$(git rev-parse remotes/gh-b/for-next)
expect="${1:-$remote}"
echo "git diff remotes/gh-b/for-next"
echo "expecting: $expect"
if ! git push gh-b b-for-next:for-next; then
# Try leased push if possible
if ! [ -z "$expect" ]; then
echo "Leased push with $expect"
if git push --force-with-lease=for-next:"$expect" gh-b b-for-next:for-next; then
echo "OK"
exit
else
echo "Lease did not work, you have to decide"
fi
fi
echo "Force push? [y/N]"
read -n 1 answer
if [ "$answer" = 'y' ]; then
git push -f gh-b b-for-next:for-next
else
echo "Ok, not pushed"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment