Creating Your First Alternate Reality
Now that we have our main universe (master branch) set up, let's create our first alternate reality!
- Create a new branch named
feature-dimension
:
git branch feature-dimension
This command creates a new branch, but doesn't switch to it yet. Think of it as creating a new parallel universe, but you're still in the original one. It's like having a blueprint for a new reality, but you haven't stepped into it yet.
You've just created a new timeline, but you're not in it yet. Let's see all the timelines we have:
git branch
You should see:
feature-dimension
* master
The *
shows which reality you're currently in. Right now, you're still in the main universe (master). The master
branch is the default branch that Git creates when you initialize a new repository.
Tips: Press q
to exit the branch list and return to your terminal.
- Let's jump into our new reality:
git checkout feature-dimension
This command does two things:
- It switches your current working directory to the
feature-dimension
branch.
- It updates the files in your working directory to match the state of the
feature-dimension
branch. It's like stepping through a portal into the new reality.
Now if you run git branch
again, you'll see:
* feature-dimension
master
The *
has moved, showing that you've successfully jumped to your new dimension! You're now working in this alternate reality.
Alternatively, you can use git switch feature-dimension
to achieve the same result. git switch
is a newer command introduced in Git 2.23 that is specifically designed for branch switching, making it clearer and more intuitive. Both commands achieve the same result, but git switch
is generally preferred for its clarity.
Don't worry if you don't see any changes in your files yet. When you create a new branch, it starts as an exact copy of the branch you were on. The exciting part comes when we start making changes! These initial copies ensure that each reality starts with the same foundation.
Pro tip: In newer versions of Git, you can create a new branch and jump to it in one command: git checkout -b feature-dimension
or git switch -c feature-dimension
. It's like creating and stepping into a portal in one swift move! Using -b
with git checkout
or -c
with git switch
combines branch creation and switching into a single step.
If you ever get lost and can't remember which dimension (branch) you're in, just run git branch
again. The branch with the *
is your current location. It's like checking your location on a map of the multiverse.