Skip to content

Instantly share code, notes, and snippets.

@chuckntaylor
Last active July 19, 2024 13:48
Show Gist options
  • Save chuckntaylor/6fef7aebc22350c7974abf08e344a61d to your computer and use it in GitHub Desktop.
Save chuckntaylor/6fef7aebc22350c7974abf08e344a61d to your computer and use it in GitHub Desktop.

Revisions

  1. chuckntaylor revised this gist Jul 19, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitRenameLocalAndRemote.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ git push origin <new_name>
    ```

    Delete the old branch on the remote repository:
    NOTE: With GitHub, you can't delete a branch through the web interface if it's the default branch of the repository. You can change the default branch in the repository settings.
    ** NOTE: With GitHub, you can't delete a branch through the web interface if it's the default branch of the repository. You can change the default branch in the repository settings. **

    ```bash
    git push origin :<old_name>
  2. chuckntaylor revised this gist Jul 19, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gitRenameLocalAndRemote.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ git push origin <new_name>
    ```

    Delete the old branch on the remote repository:
    NOTE: With GitHub, you can't delete a branch through the web interface if it's the default branch of the repository. You can change the default branch in the repository settings.

    ```bash
    git push origin :<old_name>
  3. chuckntaylor revised this gist Jul 19, 2024. 1 changed file with 40 additions and 1 deletion.
    41 changes: 40 additions & 1 deletion gitRenameLocalAndRemote.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,40 @@
    ‎‎​
    # Renaming both a local and remote branch

    First, rename the local branch by typing:

    ```bash
    git branch -m <old_name> <new_name>
    ```

    Then push the new branch to the remote repository:

    ```bash
    git push origin <new_name>
    ```

    Delete the old branch on the remote repository:

    ```bash
    git push origin :<old_name>
    ```

    Finally, reset the upstream branch for the new_name local branch:

    ```bash
    git push origin -u <new_name>
    ```

    # Renaming a remote branch

    If you only want to rename a remote branch, you can do so by:

    ```bash
    git push origin <old_name>:<new_name>
    git push origin :<old_name>
    ```

    Finally, reset the upstream branch for the new_name local branch:

    ```bash
    git push origin -u <new_name>
    ```
  4. chuckntaylor created this gist Jul 19, 2024.
    1 change: 1 addition & 0 deletions gitRenameLocalAndRemote.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎​