CodeBlanks Logo Icon CodeBlanks

Branch list

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 branch

Use 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 -a

For 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

terminal
print("Dal listesi hazırlanıyor")

Sample solution

terminal
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

Question
git branch ____
Answer
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

All lessons in Intermediate

20 Intermediate final

  1. Branch management
  2. Rebase
  3. Conflict
  4. PR flow