To rename a git branch from its name master to main make use of the git branch command with -m or --move option.
Let us see few examples:
% git branch
master
* ticket-123
As you can see, I have two branches currently for my repo and one of them is master which I want to rename as main.
% git branch --move master main
% git branch
main
* ticket-123
As you can see after using the move option along with git branch command the master branch was renamed to main successfully!
Note: If the main branch already exists you will get an error!
% git branch --move master main
fatal: a branch named 'main' already exists

Have Questions? Post them here!
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- Github: How to Invite Collaborators
- Git Commit - Author identity unknown, Please tell me who you are email
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- Get List of all local branches git command
- Git Revision Questions Before the Interview
- git fatal: Authentication failed error [fix]
- How to Install Git on Ubuntu Linux
- GitHub: How to Search Code
- How to change Git Default Author and Committer details in Eclipse
- How to check your installed version of Git
- Install GitHub Command Line Tool on Mac
- How to Merge Branch into Master Branch
- Perform an Empty Commit in Git without anything in Staging Area
- Git Fix: fatal: refusing to merge unrelated histories Error
- How to undo last Git Commit on Local Repository?
- git command to remove/unstage files from staging area
- Step-by-Step: Setting up Docker + Ubuntu Linux + Git + GitHub Tutorial
- Remove git config at Local, Global or System Levels?
- Fix [oh-my-zsh] Cant update: not a git repository
- Git Config Command - A Deep Dive
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to change directory in Git bash
- Android Error Unexpected cast to Button: layout tag was FrameLayout - Android
- cURL HTTP GET request command examples - HowTos
- Java location in Mac OS X - Mac-OS-X
- Best way to Convert Primitive long to int in Java with some Cautions - Java
- Bash getopts Command Example - Bash
- Failed to install Android.apk on device 'emulator-5554': timeout - Android-Studio
- How to Enable or Disable Dark Mode on macOS Ventura 13 - MacOS
- How to hide quick launch in SharePoint classic site - SharePoint