{"id":1496,"date":"2023-06-17T22:40:45","date_gmt":"2023-06-17T17:10:45","guid":{"rendered":"https:\/\/mutesoft.com\/spaces\/software\/?p=1496"},"modified":"2023-06-17T22:40:46","modified_gmt":"2023-06-17T17:10:46","slug":"git-how-to-rename-a-git-branch-locally-and-remotely","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/software\/git-how-to-rename-a-git-branch-locally-and-remotely.html","title":{"rendered":"Git: How to Rename a Git Branch Locally and Remotely"},"content":{"rendered":"\n<p>If you made an error while typing the branch name or decided to change the branch name after pushing it to the remote repository, there is a method to rename the branch both locally and remotely.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-how-to-rename-a-git-branch-locally-and-remotely.html\/#1_Rename_the_Local_Branch\" >1. Rename the Local Branch<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-how-to-rename-a-git-branch-locally-and-remotely.html\/#2_Delete_the_Old_Branch_Remotely_and_Push_the_New_Branch_Name\" >2. Delete the Old Branch Remotely and Push the New Branch Name<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mutesoft.com\/spaces\/software\/git-how-to-rename-a-git-branch-locally-and-remotely.html\/#3_Reset_the_Upstream_Branch\" >3. Reset the Upstream Branch<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Rename_the_Local_Branch\"><\/span>1. Rename the Local Branch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Switch to the branch\ngit checkout &lt;old_name>\n\n# Rename the local branch \ngit branch -m &lt;new_name><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Delete_the_Old_Branch_Remotely_and_Push_the_New_Branch_Name\"><\/span>2. Delete the Old Branch Remotely and Push the New Branch Name<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Delete the old branch\n# Push the new branch name\ngit push origin :&lt;old_name> &lt;new_name><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Reset_the_Upstream_Branch\"><\/span>3. Reset the Upstream Branch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Reset the upstream\ngit push origin -u &lt;new_name><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you made an error while typing the branch name or decided to change the branch name after pushing it to the remote repository, there is a method to rename the branch both locally and remotely.<\/p>\n","protected":false},"author":2,"featured_media":1053,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"If you made an error while typing the branch name or decided to change the branch name after pushing it to the remote repository, there is a method to rename the branch both locally and remotely.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[32,8],"tags":[41,31,36],"class_list":["post-1496","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","category-troubleshooting","tag-command-line","tag-git","tag-tools"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/1496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/comments?post=1496"}],"version-history":[{"count":4,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/1496\/revisions"}],"predecessor-version":[{"id":1502,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/1496\/revisions\/1502"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media\/1053"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media?parent=1496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/categories?post=1496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/tags?post=1496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}