bashbeginner

Rename Git Branch (Local and Remote)

Commands to rename a local and remote Git branch including updating tracking references.

bash
# Rename current branch
git branch -m new-name

# Rename a different branch
git branch -m old-name new-name

# Update the remote (delete old, push new)
git push origin --delete old-name
git push origin new-name

# Reset upstream tracking
git push --set-upstream origin new-name

# Verify the rename
git branch -a

# If other team members have the old branch checked out:
# They need to run:
git fetch --all --prune
git checkout new-name
git branch -D old-name

Use Cases

  • Fixing branch naming convention mistakes
  • Renaming default branch from master to main
  • Updating branch names to match ticket IDs

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.