Rename master to main

The symptom

An older Git installation created your branch as master, but every modern tutorial — and GitHub itself — assumes main. The mismatch usually surfaces when you paste a tutorial's push command:

What you see

Terminal
$ error: src refspec main does not match any
In VS Code
  1. The status bar (bottom-left) shows master where the tutorial's screenshots show main

What you see when you push to main but your branch is called master. This is Git's message, not a command to run.

What it means

A branch name is just a label — neither master nor main is special to Git. New GitHub repos (and new Git versions) default to main, older setups used master. Renaming is safe: your history, commits and files are untouched; only the label changes.

Rename locally and push

The rename

Terminal
$ git branch -m master main
$ git push -u origin main
In VS Code
  1. Command Palette → Git: Rename Branch… → type main
  2. Then Publish Branch to put main on GitHub

-m = move/rename. The push creates main on GitHub alongside the old master.

Point GitHub at main

GitHub still thinks master is the repo's default branch (the one PRs target and visitors see). Switch it, then delete the old branch:

Switch the default, delete the old

Terminal
$ git push origin --delete master
In VS Code
  1. On github.com: your repo → Settings → General → Default branch → click the switch icon → pick main
  2. Run the delete command only after switching — GitHub refuses to delete the current default branch

Never see master again

Make main the default for new repos

Terminal
$ git config --global init.defaultBranch main
In VS Code
  1. One-time terminal setting — every future git init starts on main

Tip: renaming a branch other people work on? Tell them first — their clones still point at the old name, and each teammate runs the same git branch -m locally after pulling.

Up next: the one-page Cheat Sheet — every command, its VS Code equivalent, and what it means.

FAQ

Frequently Asked Questions

Why do some repos use master and others main?
Older Git versions created master by default; GitHub and newer Git default to main. Functionally they're identical — a branch name is just a label, and neither is special to Git.
Does renaming master to main break anything?
Your history and files are untouched — it's only a label change. The things to update: push the new name (git push -u origin main), switch GitHub's default branch in Settings, and tell teammates so they rename their local copies too.
What does "src refspec main does not match any" mean?
You told Git to push a branch called main, but no branch with that name exists — yours is probably still called master. Either push master, or rename it first with git branch -m master main.
How do I make new repos start on main?
One-time setting: git config --global init.defaultBranch main. Every future git init then creates main from the start.