Converting a Git master Branch to main
Tags: github, tutorial, azure
Published: 2021-11-15 02:58:56

Many organizations began to be aware of and change non-inclusive language in the second decade of the 21st century. Many of those changes affected technology, including the choice for `git` to replace `master` with `main` for the default repo branch to avoid connotations with slavery.

While GitHub took actions to ensure new repos created on the site used `main`, older projects still used `master` as the default branch. In addition, some generator libraries still create new projects with `master` as the default and Azure DevOps also creates new repos with `master` as the default.

I had some time between projects at work in the last week and I wanted to tackle making the change for some organization repos I created to manage SQL objects and SSIS projects. This will allow all developers and contributors to have a common reference regardless of repo. There is a small process involved in making the change, as well as communicating the change to any other developers or contributors to the repo.

## Rename `master` to `main` and push to remote

- In the local environment, open a terminal and navigate to the project to be updated
- Move (rename) the `master` branch to `main`
```bash
git branch -m master main
```
- Push the new branch to the remote
```
git push -u origin main
```

## Reset default branch on GitHub

I use GitHub for my personal projects.  

- Choose **Settings** > **Branches**; `master` will display as the default branch  
![GitHub master as default](https://kristenkinnearohlmann.dev/static/49e545a34ff47fd332989e72cc19a5ea/11ff9/personal-100days-01-settings-branches.jpg)
- Click the arrows icon to **Switch to another branch**  
![GitHub switch to another branch as default](https://kristenkinnearohlmann.dev/static/492607f81c6f457b44ee008cfc19f459/3b78f/personal-100days-02-switch.jpg)
- Select the new `main` branch and click **Update**
![GitHub select main branch](https://kristenkinnearohlmann.dev/static/43836c981780dd10415421e41a6ab8f8/7aa7d/personal-100days-03-switch-main.jpg)
- Acknowledge the warning for changing the default branch (ideally, you will communicate separately with others working in this repo that the default branch has changed)  
![GitHub acknowledge warning](https://kristenkinnearohlmann.dev/static/396bfc3c50cce9c32c86955655ec8801/52eca/personal-100days-04-switch-main-confirm.jpg)
- A message will display confirming the change  
![GitHub default branch changed](https://kristenkinnearohlmann.dev/static/8a68aee61a1b8c2dddb5db0c93c653fb/37c2d/personal-100days-05-switch-main-confirm-notif.jpg)
- Review the branches for the project and confirm that `main` is set as the default  
![GitHub main default](https://kristenkinnearohlmann.dev/static/3194ec823fca5f5b233d3266c0f679ae/7f450/personal-100days-06-final.jpg)

## Reset default branch Azure DevOps

My organization uses Azure Devops for version control.

- Choose **Repos** > **Branches**  
![Azure DevOps branches](https://kristenkinnearohlmann.dev/static/0a7f3cf1022d08ab12de8046819d68e0/7b996/azdo-01-branches.jpg)
- Click the 3 dots menu on the `main` record and choose **Set as default branch**  
![Azure DevOps set main as default](https://kristenkinnearohlmann.dev/static/28cd375aada425d6e0088eba9ad1cfc5/f2a9a/azdo-02-branches-set-main-default.jpg)
- Confirm the change to `main` as the default branch  
![Azure DevOps confirm main](https://kristenkinnearohlmann.dev/static/91af972b9d5eaa99c2f7c725e371eab7/f2a9a/azdo-03-branches-main-default.jpg)

## Post-conversion

In each case, I plan to leave the `master` branch in place for about a week before removing it. At my work organization, I am in the process of informing other contributors about the need to change to using `main`.