#!/bin/sh # Move a branch to a commit, whether or not it is checked out # # Usage: git point-branch-at [] set -eu case $# in 1) _branch=$(git rev-parse --abbrev-ref HEAD); _commit=$1 ;; 2) _branch=$1; _commit=$2 ;; *) echo "Usage: git point-branch-at [] " >&2; exit 2 ;; esac if [ "$_branch" = "$(git rev-parse --abbrev-ref HEAD)" ]; then exec git reset --keep "$_commit" else exec git branch --force "$_branch" "$_commit" fi