Skip to content

Instantly share code, notes, and snippets.

@jcbrinfo
Created June 30, 2016 14:31
Show Gist options
  • Select an option

  • Save jcbrinfo/1b14520ccf28352c2f0f285b2f3e679d to your computer and use it in GitHub Desktop.

Select an option

Save jcbrinfo/1b14520ccf28352c2f0f285b2f3e679d to your computer and use it in GitHub Desktop.
Re-author the head of the specified branches.
#! /bin/sh
# Re-author the head of the specified branches of `origin`.
working_branch="$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --always 2>/dev/null)"
[ -n "$working_branch" ] || exit
git stash || exit
reset_status() {
git checkout "${working_branch}"
git stash pop
}
rollback() {
reset_status
exit "$1"
}
git pull || true
for branch in "$@"; do
git checkout "${branch}" || rollback "$?"
git commit -C HEAD --amend --reset-author || rollback "$?"
git push -f -- origin "${branch}" || rollback "$?"
done
reset_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment