Skip to content

Instantly share code, notes, and snippets.

@bradymholt
Created April 29, 2021 00:54
Show Gist options
  • Save bradymholt/e303bb2bdda2d99bbe689480154af30c to your computer and use it in GitHub Desktop.
Save bradymholt/e303bb2bdda2d99bbe689480154af30c to your computer and use it in GitHub Desktop.
git-move
git-move() {
echo "Moving commits on current branch to a new branch..."
# This is useful if commits were mistakenly made on master and need to be move to a new branch.
# $1 - New target branch name
if [ -z "$1" ]; then echo "New branch name required!"; exit 0; fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Moving local commits on ${CURRENT_BRANCH} to $1"
git branch ${1} && git reset --hard origin/${CURRENT_BRANCH} && git checkout ${1}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment