0
0
Gitdevops~20 mins

Listing branches in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Branch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of 'git branch' after creating two branches?
You have a Git repository with the default branch named main. You run these commands:

git branch feature1
git branch feature2

Then you run git branch. What is the output?
Git
git branch feature1
git branch feature2
git branch
A
  main
  feature1
  feature2
B
* feature1
  feature2
  main
C
* main
* feature1
* feature2
D
  feature1
  feature2
* main
Attempts:
2 left
💡 Hint
The asterisk (*) marks the current branch.
💻 Command Output
intermediate
1:30remaining
What does 'git branch -r' show?
You cloned a repository and run git branch -r. What does this command list?
Git
git branch -r
ALists all remote-tracking branches
BLists all local branches
CLists all branches including local and remote
DLists all tags in the repository
Attempts:
2 left
💡 Hint
Remote branches are branches on the server you cloned from.
Configuration
advanced
2:00remaining
How to list branches sorted by last commit date?
You want to list all local branches sorted by the date of their last commit, most recent first. Which command achieves this?
Agit branch --sort=-committerdate
Bgit branch --sort=authorname
Cgit branch --sort=refname
Dgit branch --sort=-authordate
Attempts:
2 left
💡 Hint
The --sort option can sort by commit dates; the minus sign reverses order.
Troubleshoot
advanced
2:00remaining
Why does 'git branch' show no branches after cloning?
You cloned a remote repository with git clone https://example.com/repo.git. Then you run git branch and see no output. Why?
AThe repository has no branches on the remote
BYou cloned with --bare option, so no local branches exist
CYou are in a detached HEAD state after cloning
DYou need to run 'git fetch' to get branches
Attempts:
2 left
💡 Hint
Bare repositories do not have working copies or local branches.
Best Practice
expert
2:30remaining
Which command safely lists all branches including remote and local with verbose info?
You want to see all branches, local and remote, with last commit info, in a single command. Which is the best command?
Agit branch -r -v
Bgit branch --all --sort=-committerdate
Cgit branch -a -v
Dgit branch -v --merged
Attempts:
2 left
💡 Hint
The -a option shows all branches, -v adds commit info.