Chapter 8: git branch

Renaming the default branch

face Josiah Wang

So far you have been making commits on a single default branch.

This is conventionally named either main or master.

If you browse to your robot project folder, you can check the name of your current branch using git branch.

user@MACHINE:~/robot$ git branch
* master

In my example, you can see that my default branch is called master.

The asterisk * is the HEAD pointer. So you are currently working on the master branch.

Now, the default branch has historically been called master by default.

There is a move since 2020 to rename the default branch to main as there is a concern that some people might find the term master offensive.

Figure taken from Know Your Meme

Websites such as GitHub and the department’s GitLab (that you will be using) now name their default branches main.

If your branch is already called main, then great! There is no need to do anything more!

If your branch is called master, it is better to rename it to main to avoid future compatibility issues. I will do that with my robot project repo now!

To rename a branch from master to main, do the following: (-m is short for --move)

user@MACHINE:~/robot$ git branch -m master main
user@MACHINE:~/robot$ git branch
* main

Now, my default branch has been renamed to main. 🎉🎉🎉

Of course, you can name your default branch to whatever you like. Just be careful changing it mid-project if you are working collaboratively with someone else!