21. Changes in the main branch

Goals

  • Learn how to work with several branches with different (sometimes conflicting) changes.

As I mentioned previously, Git lets you work with several branches at the same time. It is very useful when working in a team because people can work on different features in parallel. It is also useful when working solo: while developing features in separate branches, you can still fix bugs and release minor updates using stable code in the main branch.

01 Create the README file

Let's create a README file. It will explain what our project is about.

File: README

This is the Hello World example from the GitHowTo tutorial.

02 Commit the README file to the main branch

We are currently in the style branch. The README file is not part of this branch, so we must switch to the main branch before committing the changes.

Run

git switch main
git add README
git commit -m "Added README"

Result

$ git switch main
Switched to branch 'main'
$ git add README
$ git commit -m "Added README"
[main ee16740] Added README
 1 file changed, 1 insertion(+)
 create mode 100644 README