Create a Branch

Learn different methods for branch creation in Git.

So far, we’ve learned the basic commands to keep adding changes as snapshots. It’s time to learn some more techniques.

In this chapter, we’ll learn to do the following:

  • We’ll learn to create branches.
  • We’ll learn to check out a specific commit.
  • We’ll learn to merge branches.
  • We’ll learn check the difference between commits.
  • We’ll learn to keep a clean commit history.
  • We’ll work with git add interactively to select only the changes we want to commit.

Create a branch

We can create a branch using git switch -c. For example, the following command creates a branch named new_feature:

$ git switch -c new_feature

This creates a new branch. But actually, nothing really changes here until we create new commits. When we git log the commits, we still see the same commits graph. The only difference is now there’s a new_feature branch name that appears where the HEAD is at.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy