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 abc0b87..513c327 100644 --- a/content/notes/2020/06/2020-06-25--git-main.md +++ b/content/notes/2020/06/2020-06-25--git-main.md @@ -13,7 +13,18 @@ For new repositories, Gitea already has [the option to set the default branch na 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 checkout master; git branch -m master main; git push -u origin main; git push --delete origin master +``` + +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 ``` 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. + +*Update 1* Thanks to [Charles Pence](https://charlespence.net/) for reminding me to add the `git push --delete origin master` line.