We are going to rename the primary Git branch from master to main so your CI does not throw a tantrum and new contributors do not accidentally create more masters. This is a practical git branch rename tutorial that covers local changes remote updates and how to keep other clones and CI happy.
If you are sitting on the master branch and want to keep your working tree intact run this single command. It moves the branch pointer and keeps your files where they are.
git branch -m master main
If you were on another branch you can rename a specific branch from elsewhere by running git branch -m oldname newname while not checked out on the branch to be renamed.
Send the new branch to the remote and tell your local repo to track it. This makes future push and pull calls behave normally.
git push -u origin main
Now remove the old remote branch so the project does not keep an obsolete master that confuses contributors and tooling.
git push origin --delete master
Tell the remote to update its symbolic default branch reference and then change the default branch setting on your hosting provider like GitHub or GitLab through the web UI. Doing both prevents surprises when opening the repo in a browser.
git remote set-head origin -a
Each contributor and each CI runner needs a tiny refresh or they might accidentally recreate master or keep deploying from the wrong branch. Share these commands with your team.
git fetch origin
git branch -u origin/main main
git branch -d master
or use -D
if you are stubborn and sure about losing local commitsCI scripts deploy configs automation and docs may mention master by name. Grep the repo and update anything that would break when the default branch is main.
git grep -n "master" || true
Replace occurrences in deployment scripts CI yaml files and documentation. Also update any webhooks or service settings that target master explicitly.
Done. Your repo now uses main as the primary branch. Tell your team to run a fetch and then either delete their local master or rebase any in flight work onto main. If anyone panics tell them change is part of life and Git is designed to survive it.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.