Test Single vs Multiple Branches
In the previous steps, we saw that our repository currently has only one branch, master
. Now, let's create a new branch to see how Git handles multiple timelines.
We'll create a new branch called feature/add-greeting
. This is a common naming convention for branches that are adding a new feature.
Make sure you are in the ~/project/my-time-machine
directory:
cd ~/project/my-time-machine
Now, create the new branch using the git branch
command followed by the name of the new branch:
git branch feature/add-greeting
This command doesn't produce any output, but it has created a new branch.
Let's verify that the new branch exists by listing the branches again:
git branch
You should now see output like this:
* master
feature/add-greeting
Notice that both master
and feature/add-greeting
are listed. The *
is still next to master
, indicating that we are currently still on the master
branch. We have created a new timeline, but we haven't switched to it yet.
Now, let's use our wc -l
trick again to count the branches:
git branch | wc -l
This time, the output should be:
2
This confirms that we now have two branches in our repository.
This demonstrates the power of Git branches. You can have multiple independent lines of development within the same repository. This is incredibly useful for working on different features simultaneously or for experimenting with new ideas without affecting the main project.
In the next lab, we will learn how to switch between these branches and start making changes on our new feature/add-greeting
timeline!