Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»GIT»How To Rename a Local and Remote Git Branch

    How To Rename a Local and Remote Git Branch

    RahulBy RahulFebruary 5, 20192 Mins ReadUpdated:July 15, 2021

    Git is commonly used as a version control system for any application. Which is helpful for tracking changes in any set of source files. A branch in Git represents an independent line of development with a unique set of code changes with a unique name.

    This tutorial will help you to Rename a Git branch on a local repository. Also, we will apply the change to the remote git repository.

    Rename a Git Branch in Local

    You can use git branch -m followed by branch name to rename a git branch on your local repository.

    1. First, switch to the branch you want to rename.
      git branch <old_branch_name> 
      
    2. Next, check the current active branch
      git branch 
      

      An asterisk (*) symbol denotes the currently active branch.

    3. Finally rename a git branch with the following command. Before executing, make sure to replace the <new_branch_name> with your branch name.
      git branch -m <new_branch_name>
      

    That’s it. You have successfully renamed the current branch in the local git repository. Again run git branch to list branch names.

    Rename a Git Branch on Remote

    First, rename the branch name in the local repository with the above instructions. Then push the new branch to the remote repository.

    git push origin -u <new_branch_name>
    

    Check your remote repository and you will find the new branch there. However, the old branch will still be visible. To fix this, remove the old branch by running the following command.

    git push origin --delete <old_branch_name>
    

    Conclusion

    This tutorial describes you rename a Git branch on local and remote repositories.

    branch git
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Manually Upgrade phpMyAdmin on Ubuntu
    Next Article How to Configure Static IP Address on Fedora Desktop

    Related Posts

    How To Add a Git Remote Repository

    3 Mins Read

    How to Git Reset to Head

    Updated:November 3, 20213 Mins Read

    How to Delete a File on Git

    3 Mins Read

    How to Git Stash Changes

    Updated:October 29, 20213 Mins Read

    How to delete Git tags

    Updated:October 25, 20211 Min Read

    How to Create Git tags

    Updated:October 25, 20212 Mins Read

    1 Comment

    1. Fabian on March 9, 2019 9:05 pm

      Thanks for the post

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.