diff --git a/content/notes/2020/06/2020-06-25--git-main.md b/content/notes/2020/06/2020-06-25--git-main.md index 3deccdd..e7987d7 100644 --- a/content/notes/2020/06/2020-06-25--git-main.md +++ b/content/notes/2020/06/2020-06-25--git-main.md @@ -8,21 +8,26 @@ published: true For a while, we've all been seeing the "switch git default branch from master to main" posts, the earliest I recall having been [written by Scott Hanselman](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx). I've been postponing the change for a bit, but it was [the post by Kristófer Reykjalín](https://www.thorlaksson.com/im-changing-the-default-branch-name-in-my-git-repositories-and-you-should-too/) that gave the required motivation to go out and just do it. -For new repositories, Gitea already has [the option to set the default branch name](https://github.com/go-gitea/gitea/pull/10803). +For new repositories, [Gitea](https://gitea.io) already has [the option to set the default branch name](https://github.com/go-gitea/gitea/pull/10803). For exiting repositories, the [commands provided by Scott](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx) work perfectly: ``` -git checkout master; git branch -m master main; git push -u origin main; git push --delete origin master +git checkout master; git branch -m master main; git push -u origin main ``` Yes, a one-liner :) If you like to take things more slowly, here it goes: ``` -git checkout master # switch to master branch -git branch -m master main # move existing master branch to main (keeping history) -git push -u origin main # push the main branch to the server -git push --delete origin master # delete the master from the server +git checkout master # switch to master branch +git branch -m master main # move existing master branch to main (keeping history) +git push -u origin main # push the main branch to the server +``` + +If you use [Gitea](https://gitea.io), you should now go the repository's Settings > Branches and set the main branch as the default branch. Once done, you can now safely delete the obsolete master branch with the command below. + +``` +git push --delete origin master # delete the master from the server ``` As for my website, here's the [commit](https://git.yarmo.eu/yarmo/yarmo.eu/commit/78e18c55c59c8e65e99013718cd42154ddb7ebd6) that completed the transition, making sure my CI/CD solution knows what to listen to. @@ -32,3 +37,9 @@ As for my website, here's the [commit](https://git.yarmo.eu/yarmo/yarmo.eu/commi ## Update 1 Thanks to [Charles Pence](https://charlespence.net/) for reminding me to add the `git push --delete origin master` line. + +--- + +## Update 2 + +Thanks to [Charles Pence](https://charlespence.net/) for reminding me that a Gitea branch cannot be deleted as long as it's the default.