Created
April 29, 2021 00:54
-
-
Save bradymholt/e303bb2bdda2d99bbe689480154af30c to your computer and use it in GitHub Desktop.
git-move
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
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