---
title: Renaming a Local and Remote Git Branch
description: Sometimes you need to rename a Git branch, here are the simple commands rename a local or remote branch in Git using the command line.
date: 2022-03-31
tags: Git
source: https://brianchildress.co/blog/renaming-local-and-remote-git-branch
---

# Renaming a Local and Remote Git Branch

Sometimes you need to rename a Git branch, here are the simple commands rename a local or remote branch in Git using the command line.

## Updating Local Branch

1. Switch to the local branch you want to rename
   ```sh
   git checkout <old branch name>
   ```
2. Rename the branch by using the `-m` flag:
    ```sh
    git branch -m <new branch name>
    ```

    **Note: if you have a branch matching `new branch name` use the `-M` flag to override the existing branch with the same name


## Update Remote Branch

1. Push the new branch, resetting upstream
    ```sh
    git push origin -u <new branch name>
    ```
2. Delete the `old branch name` on the remote
    ```sh
    git push origin --delete <old branch name>
    ```
