Skip to content

Instantly share code, notes, and snippets.

@kristofk
Last active July 26, 2019 06:21
Show Gist options
  • Save kristofk/e78d896807382732f9fc01a553da44eb to your computer and use it in GitHub Desktop.
Save kristofk/e78d896807382732f9fc01a553da44eb to your computer and use it in GitHub Desktop.
Renames the current branch and locally and on remote. (gitrenamebransh.sh <remote_name> <old_branch_name> <new_branch_name>)
#!/bin/sh
# Calling this script:
# gitrenamebransh.sh <remote_name> <old_branch_name> <new_branch_name>
# Rename the local branch to the new name
git branch -m $2 $3
# Delete the old branch on remote - where <remote> is, for example, origin
git push $1 --delete $2
# Push the new branch to remote
git push $1 $2
# Reset the upstream branch for the new_name local branch
git push $1 -u $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment