Skip to content

Instantly share code, notes, and snippets.

@danieldogeanu
Last active August 3, 2025 16:05
Show Gist options
  • Save danieldogeanu/739f88ea5312aaa23180e162e3ae89ab to your computer and use it in GitHub Desktop.
Save danieldogeanu/739f88ea5312aaa23180e162e3ae89ab to your computer and use it in GitHub Desktop.

Revisions

  1. danieldogeanu revised this gist Jul 31, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RenameGitBranch.md
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,4 @@ If someone has a local clone of your repository, they can update their locals by

    Thanks Scott Hanselman for the instructions, you can read the full article here: [Easily rename your Git default branch from master to main](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx)

    If this was useful, you can [buy me a coffee here](https://www.buymeacoffee.com/danieldogeanu). Thank you!
    If this was useful, you can [buy me a coffee here](https://ko-fi.com/danieldogeanu). Thank you!
  2. danieldogeanu revised this gist Sep 24, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion RenameGitBranch.md
    Original file line number Diff line number Diff line change
    @@ -21,4 +21,4 @@ If someone has a local clone of your repository, they can update their locals by

    Thanks Scott Hanselman for the instructions, you can read the full article here: [Easily rename your Git default branch from master to main](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx)


    If this was useful, you can [buy me a coffee here](https://www.buymeacoffee.com/danieldogeanu). Thank you!
  3. danieldogeanu revised this gist Jul 19, 2020. 1 changed file with 7 additions and 14 deletions.
    21 changes: 7 additions & 14 deletions RenameGitBranch.md
    Original file line number Diff line number Diff line change
    @@ -11,20 +11,13 @@ To rename your Git master branch to main, you must do the following steps:
    4. Delete the old `master` branch by going to your GitHub repository in your browser, navigate to your branches page, and click the `Delete this branch` button (the red trash bin icon). Your `master` branch is now gone.

    If someone has a local clone of your repository, they can update their locals by following these steps:
    1. Got to the master branch:
    - `git checkout master`
    2. Rename master to main locally:
    - `git branch -m master main`
    3. Get the latest commits from the server:
    - `git fetch`
    4. Remove the link to origin/master:
    - `git branch --unset-upstream`
    5. Add a link to origin/main:
    - `git branch -u origin/main`
    6. Update the default branch to be origin/main:
    - `git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main`
    7. Delete origin/master completely:
    - `git branch --remotes -d origin/master`
    1. Got to the master branch: `git checkout master`
    2. Rename master to main locally: `git branch -m master main`
    3. Get the latest commits from the server: `git fetch`
    4. Remove the link to origin/master: `git branch --unset-upstream`
    5. Add a link to origin/main: `git branch -u origin/main`
    6. Update the default branch to be origin/main: `git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main`
    7. Delete origin/master completely: `git branch --remotes -d origin/master`

    Thanks Scott Hanselman for the instructions, you can read the full article here: [Easily rename your Git default branch from master to main](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx)

  4. danieldogeanu revised this gist Jul 19, 2020. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions RenameGitBranch.md
    Original file line number Diff line number Diff line change
    @@ -18,11 +18,13 @@ If someone has a local clone of your repository, they can update their locals by
    3. Get the latest commits from the server:
    - `git fetch`
    4. Remove the link to origin/master:
    - `git branch --unset-upstream`
    - `git branch --unset-upstream`
    5. Add a link to origin/main:
    - `git branch -u origin/main`
    - `git branch -u origin/main`
    6. Update the default branch to be origin/main:
    - `git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main`
    7. Delete origin/master completely:
    - `git branch --remotes -d origin/master`

    Thanks Scott Hanselman for the instructions, you can read the full article here: [Easily rename your Git default branch from master to main](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx)

  5. danieldogeanu revised this gist Jun 27, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions RenameGitBranch.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@ To rename your Git master branch to main, you must do the following steps:

    3. Update the tracking of the branch from your command line with the following command:
    - `git branch -u origin/main main`

    4. Delete the old `master` branch by going to your GitHub repository in your browser, navigate to your branches page, and click the `Delete this branch` button (the red trash bin icon). Your `master` branch is now gone.

    If someone has a local clone of your repository, they can update their locals by following these steps:
    1. Got to the master branch:
  6. danieldogeanu created this gist Jun 27, 2020.
    27 changes: 27 additions & 0 deletions RenameGitBranch.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    To rename your Git master branch to main, you must do the following steps:
    1. Navigate to your repository in the command line and issue the following commands:
    - `git branch -m master main`
    - `git push -u origin main`

    2. Change your default branch on GitHub by going to your GitHub repository in your browser, and navigate to `Settings > Branches` and click on the dropdown and switch from `master` to `main` and click `Update` (this will only show if you have two or more branches). The `main` branch is now your default branch.

    3. Update the tracking of the branch from your command line with the following command:
    - `git branch -u origin/main main`

    If someone has a local clone of your repository, they can update their locals by following these steps:
    1. Got to the master branch:
    - `git checkout master`
    2. Rename master to main locally:
    - `git branch -m master main`
    3. Get the latest commits from the server:
    - `git fetch`
    4. Remove the link to origin/master:
    - `git branch --unset-upstream`
    5. Add a link to origin/main:
    - `git branch -u origin/main`
    6. Update the default branch to be origin/main:
    - `git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main`

    Thanks Scott Hanselman for the instructions, you can read the full article here: [Easily rename your Git default branch from master to main](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx)