change master git code example
Example 1: 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 2: git change master branch
## 1) Rename master branch to oldmaster.
git branch -m master oldmaster
#Now there is no master branch on my local machine.
## 2) Rename my masterTemp branch to master
git branch -m masterTemp master
#The branch which was named masterTemp on my local machine is now master
## 3) Delete the branch from remote
git branch -rD master
## 4) Push the new master branch to remote
git push --force origin master