Skip to main content

5 simple steps that I tested and used to make the change in under 1 minute.

---
title: Change GitHub default branch from master to main
subtitle: 5 simple steps that I tested and used to make the change in under 1 minute.
author: Steven Mortimer
date: July 23, 2020
source: https://stevenmortimer.com/5-steps-to-change-github-default-branch-from-master-to-main/
snippet: https://jonlabelle.com/snippets/view/markdown/change-github-default-branch-from-master-to-main
gist: https://gist.github.com/jonlabelle/81206faafb56714d7499efa54eb8f3ff
notoc: false
---

1. Move the `master` branch to `main`

    ```bash
    git branch --move master main
    ```

2. Push `main` to remote repo

    ```bash
    git push --set-upstream origin main
    ```

3. Point `HEAD` to `main` branch

     ```bash
     git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
     ```

4. [Change default branch](https://docs.github.com/en/github/administering-a-repository/managing-branches-in-your-repository/changing-the-default-branch) to `main` on GitHub

    - Navigate in your browser to your [GitHub](https://github.com) repository.
    - From the left rail, click **Settings** -> **Branches** and change the default branch to `main`

5. Delete `master` branch on the remote repo

    ```bash
    git push origin --delete master
    ```

---

Your repository contributors will have to manually update their local
environments:

```bash
git branch --move master main
git fetch origin
git branch --set-upstream-to origin/main main
```

---

To [initialize](https://git-scm.com/docs/git-init#Documentation/git-init.txt---initial-branchltbranch-namegt) a new Git repository
and set the default branch to `main`:

```bash
git init --initial-branch=main
```

---

- Source: [Steven Mortimer, 5 steps to change GitHub default branch from master to main](https://stevenmortimer.com/5-steps-to-change-github-default-branch-from-master-to-main/)
- Snippet: <https://jonlabelle.com/snippets/view/markdown/change-github-default-branch-from-master-to-main>
- Gist: <https://gist.github.com/jonlabelle/81206faafb56714d7499efa54eb8f3ff>