How to Rename the master branch to main in Git

Hi All,

To be honest, i am a System Engineering guy and not a developer. Even i like to write PowerShell Scripts and use VSCode almost on a daily basis. I am still a Git Noob ??

I’ve had an old GitHub Repo where the only branch is still “master”. I wanted to change that and found this Guide.

To rename the branch locally i used the following command

git branch -m master main

Then i pushed that branch to GitHub

git push -u origin main

As you can see there are now two branches

You need to change the default branch

Now i am able to delete the master branch

git push origin --delete master

That’s it. Happy coding.

Regards
Andres Bohren