how to switch master to main code example

Example 1: change master to main git

$ git branch -m master main

Example 2: how to move master branch to main branch

# Step 1 
# create main branch locally, taking the history from master
git branch -m master main

# Step 2 
# push the new local main branch to the remote repo (GitHub) 
git push -u origin main

# Step 3
# switch the current HEAD to the main branch
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

# Step 4
# change the default branch on GitHub to main
# https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch

# Step 5
# delete the master branch on the remote
git push origin --delete master

Example 3: how to switch from master to main

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

Example 4: how to switch from master to main

Steps
Step 1 – Move the master branch to 'main'
Step 2 – Push 'main' to remote repo.
Step 3 – Point HEAD to 'main' branch.
Step 4 – Change default branch to 'main' on GitHub site.
Step 5 – Delete 'master' branch on the remote repo.