git branch
- Git course
- Beginner
- Lesson 54/80
- 4 min
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
testIn 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 branchAfter 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
# Yeni dal oluştur
# Dalları listeleSample solution
git branch development
git branchExpected 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
git branch ____
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 |