## Renaming the Local master Branch to main
The first step is to rename the "master" branch in your _local_ Git repositories:
```shell
$ git branch -m master main
```
Check if this has worked as expected:
```shell
$ git status
On branch main
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
```
The local branch has been renamed - but it is necessary to make some changes on the _remote_ repository as well!
## Renaming the Remote master Branch
The second step is to _create a new branch_ on the remote named "main" - because Git does not allow to simply "rename" a remote branch. Instead, we'll have to create a new "main" branch and then delete the old "master" branch.
Make sure your current local HEAD branch is still "main" when executing the following command:
```shell
$ git push -u origin main
```
Now there is a new branch on the remote named "main". Next, remove the old "master" branch on the remote:
```shell
$ git push origin --delete master
```
This might have worked and the renaming was successful. In many cases, however, there will be an error message like the following:
```shell
To https://github.com/gittower/git-crashcourse.git
! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'https://
[email protected]/gittower/git-crashcourse.git'
```
GitHub, like other code-hosting platforms, expects a "default" branch to be definied--and deleting this is not allowed.
Additionally, the old "master" might be set as "protected". It is necessary to resolve this in order to proceed.
Here's how to do this in GitHub:
![[github-change-default-branch.gif]]
Now, deleting "master" from the remote repository should be successful:
```shell
git push origin --delete master
```
## More Info
[Rename master main](https://www.git-tower.com/learn/git/faq/git-rename-master-to-main/)
___
**Tags**: #git #gitHub