Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»GIT»How To Rename a Local and Remote Git Branch

    How To Rename a Local and Remote Git Branch

    By RahulJuly 15, 20212 Mins Read

    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.

    Advertisement

    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

    Related Posts

    Git Change Remote URL: How to

    Git Change Remote URL in Local Repository

    Git Change Remote URL to SSH (from HTTPS)

    How to Create Branch in Git Repository

    View 1 Comment

    1 Comment

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

      Thanks for the post

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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