DEV Community

Michael Otu
Michael Otu

Posted on • Edited on

7

Change branch name from master to main

By google-ing, we'd find a simple command as git branch -m master main which should rename the master branch to main.

What if it was not successful and you had,

error: refname refs/heads/master not found
fatal: Branch rename failed
Enter fullscreen mode Exit fullscreen mode

Well, in my case, I create a new project then I initialized git. I then remembered that by default, on Github, the default branch is main and not master anymore.

You can change the name from master to main in few steps, locally before you even make a commit.

  1. Navigate to the directory where your project sits.
  2. In it, show hidden file since by default, .git would be hidden.
  3. Inside .git, there is a file, HEAD, open it in a text editor. You'd see, ref: refs/heads/master.
  4. Simple enough, change, master to main.

We just renamed the master branch as main. Verify this merely by entering, git branch from the terminal.

In an instance where the project is new locally (the project is git initialized locally), then after the first commit, git add . && git commit -m "Initial commit" we can rename the current branch with, git branch -m main`.

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (3)

Collapse
 
256hz profile image
Abe Dolinger

This helped a ton, thank you!

Collapse
 
juniormayhe profile image
Junior Mayhé

I don't know ghana languages but here we go: meda wo ase!

Collapse
 
otumianempire profile image
Michael Otu

You are welcome 😘😘

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay