Last active
January 4, 2021 18:38
-
-
Save abrown/a74b1a6f3dbc8f076b54576a5902e34d to your computer and use it in GitHub Desktop.
Rebase and push fixups from a code review
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 | |
# This script automates the process of rebasing some fixed-up commits (e.g. from a PR review) on the default branch | |
# of a remote repository. It expects changes to have been committed with `git commit --fixup ...` and to have the | |
# changed branch currently checked out. | |
# Retrieve the default branch of the origin remote. | |
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') | |
(set -x; git fetch origin $DEFAULT_BRANCH:$DEFAULT_BRANCH) | |
# Rebase the fixed-up commits on to the default branch. | |
(set -x; git rebase --autosquash $DEFAULT_BRANCH) | |
# To double-check that things look right, list the files changed by commit. | |
(set -x; git log --oneline --name-only $DEFAULT_BRANCH..HEAD) | |
# Optionally force-push the changed branch. | |
CHANGE_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
echo "Force-push to branch $CHANGE_BRANCH? [y/N]" | |
read PUSH | |
if [[ $PUSH == "y" ]]; then | |
(set -x; git push --force) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment