Branch list
- Git course
- Intermediate
- Lesson 1/82
- 4 min
Learn the local and remote branch list with git branch.
View the Branch List
Use git branch to see which local branches exist in a repository. The branch marked with an asterisk is the one you are currently working on.
git branchUse the -r option to list remote branches, or -a to see both local and remote branches.
View Local and Remote Branches Together
The git branch -a command displays local branches and known remote branches in the same list. Remote branches usually appear with the remotes/origin/ prefix.
git branch -aFor example, remotes/origin/main represents the main branch on the origin remote. This list helps you compare branches across environments.
Practice List All Branches
Write the command that lists local and remote branches together. Then print a message indicating that listing is complete.
Starter code
print("Dal listesi hazırlanıyor")Sample solution
git branch -a
print("Tüm dallar listelendi")Expected output
Dal listesi hazırlanıyor Tüm dallar listelendi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which command lists only remote branches?
- git branch -a
- git branch -m
- git branch -r Correct answer
- git branch -d
Explanation: Correct. The -r option lists only remote branch references.
2 List Remote Branches
git branch ____
git branch -r
Explanation: The -r option lists remote branches; local branches are not included in this view.
3 Branch Listing Options
| Term | Meaning |
|---|---|
git branch |
Displays local branches |
git branch -r |
Displays remote branches |
git branch -a |
Displays all known branches |
remotes/origin/main |
Remote main branch reference |