Last active
July 28, 2023 22:04
-
-
Save akash02-das/1a4e18d68ee85eb52387c9617c994da1 to your computer and use it in GitHub Desktop.
Revisions
-
akash02-das renamed this gist
Jul 28, 2023 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ ## Renaming the Local/Remote master Branch to main <img src="https://stevenmortimer.com/blog/5-steps-to-change-github-default-branch-from-master-to-main/master-to-main.png" width="600" height="350" /> * The first step is to rename the "master" branch in your local Git repositories: @@ -29,19 +29,19 @@ * Depending on your exact setup, this might have worked and the renaming is successful. In many cases, however, you will see an error message like the following one: <pre> To https://github.com/example/git-example.git ! [remote rejected] master (refusing to delete the current branch: refs/heads/master) error: failed to push some refs to 'https://[email protected]/example/git-example.git' </pre> * GitHub, like other code-hosting platforms, too, expects you to define a "default" branch - and deleting this is not allowed. Additionally, your old "master" might be set as "protected". You'll need to resolve this before you can go on. Here's how to do this in GitHub: [See this video](https://www.git-tower.com/learn/media/pages/git/faq/git-rename-master-to-main/521685b3c0-1690385124/github-change-default-branch.mp4) * If you try again now, deleting "master" from the remote repository should be successful: <pre> $ git push origin --delete master To https://github.com/example/git-example.git - [deleted] master </pre> That’s it. You have successfully renamed the master branch to main. 🥳 -
akash02-das created this gist
Jul 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ ## Renaming the Local/Remote master Branch to main <img src="https://stevenmortimer.com/blog/5-steps-to-change-github-default-branch-from-master-to-main/master-to-main.png" width="400" height="250" /> * The first step is to rename the "master" branch in your local Git repositories: <pre>$ git branch -m master main</pre> * Let's quickly check if this has worked as expected: <pre> $ git status On branch main Your branch is up to date with 'origin/master'. nothing to commit, working tree clean </pre> ## Renaming the Remote master Branch as Well * Make sure your current local HEAD branch is still "main" when executing the following command: <pre>$ git push -u origin main</pre> * We now have a new branch on the remote named "main". Let's go on and remove the old "master" branch on the remote: <pre>$ git push origin --delete master</pre> * Depending on your exact setup, this might have worked and the renaming is successful. In many cases, however, you will see an error message like the following one: <pre> To https://github.com/gittower/git-crashcourse.git ! [remote rejected] master (refusing to delete the current branch: refs/heads/master) error: failed to push some refs to 'https://[email protected]/gittower/git-crashcourse.git' </pre> * GitHub, like other code-hosting platforms, too, expects you to define a "default" branch - and deleting this is not allowed. Additionally, your old "master" might be set as "protected". You'll need to resolve this before you can go on. Here's how to do this in GitHub: <video src="https://www.git-tower.com/learn/media/pages/git/faq/git-rename-master-to-main/521685b3c0-1690385124/github-change-default-branch.mp4" width="400" height="250" /> * If you try again now, deleting "master" from the remote repository should be successful: <pre> $ git push origin --delete master To https://github.com/gittower/git-crashcourse.git - [deleted] master </pre>