Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What command lists all local branches in a Git repository?
The command git branch lists all local branches in your Git repository.
Click to reveal answer
beginner
How do you list all remote branches in Git?
Use git branch -r to list all remote branches.
Click to reveal answer
beginner
What command shows both local and remote branches in Git?
Use git branch -a to see all branches, local and remote.
Click to reveal answer
beginner
What does the asterisk (*) mean when you run git branch?
The asterisk (*) marks the branch you are currently working on (the active branch).
Click to reveal answer
intermediate
How can you list branches sorted by the last commit date?
Use git branch --sort=-committerdate to list branches sorted by the most recent commit first.
Click to reveal answer
Which command lists only local branches in Git?
Agit branch -a
Bgit branch -r
Cgit branch
Dgit branch --all
✗ Incorrect
git branch lists local branches only. -r is for remote branches, and -a or --all shows both local and remote.
What does git branch -r show?
ARemote branches
BLocal branches
CAll branches
DBranches with last commit date
✗ Incorrect
git branch -r lists only remote branches.
How do you see all branches, local and remote, in one command?
Agit branch -a
Bgit branch -r
Cgit branch
Dgit branch --remote
✗ Incorrect
git branch -a shows all branches, both local and remote.
In the output of git branch, what does the * symbol indicate?
AA remote branch
BThe current active branch
CA deleted branch
DA branch with conflicts
✗ Incorrect
The asterisk (*) marks the branch you are currently on.
Which command sorts branches by the most recent commit date?
Agit branch --sort=authorname
Bgit branch --sort=committerdate
Cgit branch -r
Dgit branch --sort=-committerdate
✗ Incorrect
git branch --sort=-committerdate sorts branches with the newest commit first.
Explain how to list local, remote, and all branches in Git.
Think about the different flags used with git branch.
You got /3 concepts.
Describe what the asterisk (*) means in the output of git branch.
It marks your current position in the project.
You got /2 concepts.
Practice
(1/5)
1. What does the command git branch show by default?
easy
A. All remote branches in the repository
B. All local branches in the repository
C. All branches, both local and remote
D. The current branch only
Solution
Step 1: Understand the default behavior of git branch
The command git branch without any options lists only the local branches in your repository.
Step 2: Differentiate from remote branches
Remote branches require the -r option, and all branches require -a. So by default, it shows local branches only.
Final Answer:
All local branches in the repository -> Option B
Quick Check:
Default git branch = local branches [OK]
Hint: No option means local branches only [OK]
Common Mistakes:
Confusing local with remote branches
Thinking it shows all branches by default
Assuming it shows only the current branch
2. Which command correctly lists all remote branches in a Git repository?
easy
A. git branch -r
B. git branch -a
C. git branch --remote-list
D. git branch --all-remote
Solution
Step 1: Identify the option for remote branches
The option -r with git branch lists all remote branches.
Step 2: Verify other options
-a lists all branches (local + remote), but the question asks only for remote branches. The other options are invalid.
Final Answer:
git branch -r -> Option A
Quick Check:
-r means remote branches [OK]
Hint: Use -r to list remote branches only [OK]
Common Mistakes:
Using -a to list only remote branches
Typing invalid options like --remote-list
Confusing remote with local branches
3. You want to list all branches but exclude remote branches from the output. Which command should you use?
easy
A. git branch -r
B. git branch -a
C. git branch
D. git branch --no-remote
Solution
Step 1: Understand the requirement
You want to list all branches but exclude remote branches, so only local branches should appear.
Step 2: Identify the correct command
git branch by default lists only local branches. git branch -a lists all branches including remote, git branch -r lists only remote branches, and git branch --no-remote is invalid.
Final Answer:
git branch -> Option C
Quick Check:
Default git branch = local branches only [OK]
Hint: No option lists local branches only [OK]
Common Mistakes:
Using git branch -a, which includes remote branches
Using invalid options like --no-remote
Confusing remote and local branch listings
4. What is the output of the command git branch -a if your repository has local branches main, dev and remote branches origin/main, origin/feature?
medium
A. * main\n dev\n remotes/origin/main\n remotes/origin/feature
B. * main\n dev
C. remotes/origin/main\nremotes/origin/feature
D. * origin/main\n origin/feature
Solution
Step 1: Understand git branch -a output format
This command lists all branches: local branches are shown plainly, remote branches are prefixed with remotes/.
Step 2: Match branches to output
Local branches main and dev appear without prefix. Remote branches appear as remotes/origin/main and remotes/origin/feature. The current branch is marked with *.
Final Answer:
* main\n dev\n remotes/origin/main\n remotes/origin/feature -> Option A
Quick Check:
-a shows all branches with remotes/ prefix [OK]
Hint: All branches show; remotes have remotes/ prefix [OK]
Common Mistakes:
Missing remotes/ prefix for remote branches
Showing only local or only remote branches
Not marking current branch with *
5. You ran git branch -r but got an error: error: unknown option '-r'. What is the likely cause?
medium
A. You need to use git remote branch instead
B. You typed git branch -r in a non-Git directory
C. You forgot to fetch remote branches first
D. You used an old Git version that does not support -r
Solution
Step 1: Analyze the error message
The error says unknown option '-r', meaning Git does not recognize the -r flag.
Step 2: Identify possible causes
This usually happens if the Git version is very old and does not support -r with git branch. Other options would give different errors or no error.
Final Answer:
You used an old Git version that does not support -r -> Option D
Quick Check:
Old Git versions lack -r option [OK]
Hint: Check Git version if options cause unknown errors [OK]
Common Mistakes:
Assuming wrong command syntax
Thinking fetch is required to list remote branches