CodeBlanks Logo Icon CodeBlanks

git branch

Learn to list and create branches with git branch.

List branches with git branch

The git branch command lists local branches in the repository. When you run it without arguments, you see the names of existing branches. The branch marked with * is the one you are currently working on.

git branch
  feature
* main
  test

In this example, the active branch is main.

Create a new branch

Use git branch branch-name to create a new branch. This command creates a new branch pointer but does not switch the current branch. The new branch starts from the commit at your current position.

git branch feature
git branch

After creating the branch, you can see that the current branch has not changed.

Practice Create and list branches

Create a new branch named development. Then list the repository branches.

Starter code

terminal
# Yeni dal oluştur

# Dalları listele

Sample solution

terminal
git branch development
git branch

Expected output

  development
* main

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does the asterisk in git branch output indicate?

  • The branch with the most commits
  • The current working branch Correct answer
  • The oldest branch
  • A deleted branch

Explanation: The asterisk identifies the branch you are currently working on.

2 Create a new branch

Question
git branch ____
Answer
git branch deneme

Explanation: To create a branch, provide its name after the <code>git branch</code> command.

3 git branch usages

Term Meaning
git branch Lists branches
git branch yeni Creates a new branch
* Marks the active branch
Dal adı Name of the pointer

All lessons in Beginner