Git Branch Creation Quiz

Git
0 Passed
0% acceptance

Master the art of parallel development. Learn how to create, name, and manage branches to isolate your work and keep your repository organized.

30 Questions
~60 minutes
1

Question 1

What is a 'branch' in Git, technically speaking?

A
A complete copy of all the files in the project.
B
A lightweight movable pointer to a specific commit.
C
A separate directory on your hard drive.
D
A connection to a remote server.
2

Question 2

Which command creates a new branch named `feature-login` but *does not* switch to it?

A
git checkout -b feature-login
B
git branch feature-login
C
git switch -c feature-login
D
git create feature-login
3

Question 3

You want to create a new branch named `bugfix/header` and switch to it immediately. Which command is the modern, recommended way to do this?

A
git branch -m bugfix/header
B
git checkout -b bugfix/header
C
git switch -c bugfix/header
D
git add branch bugfix/header
4

Question 4

Which of the following is NOT a valid branch name in Git?

A
feature/new-ui
B
bugfix_#123
C
doc update
D
v1.0.0
5

Question 5

You run `git branch` and see a list of branches. What does the asterisk `*` next to one of the names indicate?

A
It is the main branch.
B
It is the branch you are currently checked out on (HEAD points to it).
C
It is the branch with the most recent commit.
D
It is a remote branch.
6

Question 6

You want to see all branches, including those on the remote server (like `origin/main`). Which command should you use?

A
git branch --all
B
git branch --remote
C
git show-branches
D
git status --verbose
7

Question 7

You want to create a new branch `hotfix` starting from a specific commit `a1b2c3d`, not from the current HEAD. How do you do this?

A
git branch hotfix a1b2c3d
B
git checkout a1b2c3d && git branch hotfix
C
git reset a1b2c3d hotfix
D
Both A and B work.
8

Question 8

What is the purpose of using slashes in branch names, like `feature/login-page` or `users/john/experiment`?

A
It creates actual subdirectories in the `.git/refs/heads` folder, helping to organize branches hierarchically.
B
It is required for compatibility with GitHub.
C
It tells Git to merge these branches automatically.
D
It has no technical effect; it is just a visual convention.
9

Question 9

You try to create a branch named `HEAD`. Git rejects this. Why?

A
Branch names must be at least 5 characters long.
B
`HEAD` is a reserved reference name used by Git to track the current checkout.
C
Branch names cannot be uppercase.
D
You already have a branch named `head`.
10

Question 10

Which command provides a visual text-based graph of your branches and merge history in the terminal?

A
git graph
B
git log --graph --oneline --all
C
git show-branch --graphic
D
git status --graph
11

Question 11

You are in a 'detached HEAD' state. You want to save your current state into a new branch named `backup`. What command do you run?

A
git checkout -b backup
B
git save backup
C
git branch -m backup
D
git commit -b backup
12

Question 12

You want to rename your current branch from `fetaure-x` (typo) to `feature-x`. Which command does this?

A
git branch -m feature-x
B
git rename feature-x
C
git mv fetaure-x feature-x
D
git config branch.name feature-x
13

Question 13

Which command lists only the branches that have already been merged into your current branch?

A
git branch --merged
B
git branch --status=merged
C
git log --merged
D
git show --merged
14

Question 14

You create a branch `new-feature`. Does this action duplicate all the files in your project folder?

A
Yes, that is how version control works.
B
No, it only creates a small reference file pointing to the current commit.
C
Yes, but only the modified files.
D
No, it creates a symlink to the project folder.
15

Question 15

You want to create a branch `v1.0-maintenance` starting specifically from a tag named `v1.0`. What is the command?

A
git branch v1.0-maintenance v1.0
B
git checkout v1.0 -b v1.0-maintenance
C
git switch -c v1.0-maintenance v1.0
D
All of the above.
16

Question 16

What happens if you try to create a branch with a name that already exists?

A
Git overwrites the old branch with the new one.
B
Git creates a copy with a number suffix (e.g., branch-2).
C
Git returns a fatal error: 'A branch named ... already exists'.
D
Git merges the two branches.
17

Question 17

You want to see the last commit on each branch along with the branch name. Which flag adds this detail to the list?

A
git branch -v
B
git branch --last
C
git branch --info
D
git branch --commits
18

Question 18

You want to create a completely empty branch with no parents and no files (e.g., for documentation or a completely separate project). Which command does this?

A
git checkout --orphan new-branch
B
git branch --empty new-branch
C
git init --branch new-branch
D
git switch --clean new-branch
19

Question 19

How does Git know which branch is the 'default' branch (the one checked out when you clone)?

A
It is always named 'main'.
B
It is determined by the remote repository's HEAD reference.
C
It is the branch with the most commits.
D
It is alphabetical.
20

Question 20

You want to check which branches contain a specific commit (e.g., a bug fix `fix-123`). Which command helps?

A
git branch --contains fix-123
B
git log --grep fix-123
C
git show fix-123
D
git branch --search fix-123
21

Question 21

You accidentally deleted a branch that had work on it! You remember the branch name was `feature-z`. How can you find the commit SHA it pointed to so you can restore it?

A
git reflog
B
git log --deleted
C
git recover feature-z
D
You cannot; it is gone forever.
22

Question 22

Are branch names case-sensitive in Git?

A
Yes, always.
B
No, never.
C
It depends on the operating system's filesystem.
D
Yes for local branches, no for remote branches.
23

Question 23

You want to set a description for a branch to explain its purpose (without adding a commit). Which command allows this?

A
git branch --edit-description
B
git describe branch
C
git label branch
D
Git branches cannot have descriptions.
24

Question 24

What is the difference between `git branch -d` and `git branch -D`?

A
They are the same.
B
`-d` deletes local branches, `-D` deletes remote branches.
C
`-d` is a safe delete (checks for merge), `-D` is a force delete.
D
`-d` deletes the pointer, `-D` deletes the commits.
25

Question 25

You want to list branches sorted by the date of their last commit. Which command works?

A
git branch --sort=-committerdate
B
git branch --order=date
C
git branch --recent
D
git show-branch --sorted
26

Question 26

You want to create a branch `feature` that tracks `origin/feature` automatically. Which command does this?

A
git checkout feature
B
git branch --track feature origin/feature
C
git checkout -b feature origin/feature
D
All of the above (assuming `feature` doesn't exist locally).
27

Question 27

What does the command `git branch --no-merged` show?

A
Branches that have been merged but not deleted.
B
Branches that contain work that has NOT yet been merged into the current branch.
C
Branches that have no commits.
D
Branches that are conflicting.
28

Question 28

You want to verify exactly which commit a branch named `release` points to. Which command gives just the SHA-1?

A
git rev-parse release
B
git show release
C
git branch --sha release
D
git log release
29

Question 29

Can you have two branches pointing to the exact same commit?

A
No, that would be a conflict.
B
Yes, this is very common.
C
Only if one is local and one is remote.
D
Only if the repository is bare.
30

Question 30

You want to change the default branch name for *all* new repositories you create on your computer from 'master' to 'main'. What is the command?

A
git config --global init.defaultBranch main
B
git branch --set-default main
C
git config --system branch.default main
D
git init --main