0
0
Gitdevops~20 mins

What a branch is (pointer to a commit) in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Branch Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does a Git branch actually point to?

In Git, a branch is often described as a pointer. What exactly does this pointer reference?

AA branch points to a specific commit in the repository's history.
BA branch points to a remote repository URL.
CA branch points to a file in the working directory.
DA branch points to the latest tag in the repository.
Attempts:
2 left
💡 Hint

Think about what Git uses to track changes and history.

💻 Command Output
intermediate
2:00remaining
Output of 'git branch' command

What is the output of the git branch command immediately after creating a new branch named feature and switching to it?

Commands run:

git branch feature
git checkout feature
git branch
A
* main
  feature
B
  feature
* main
C
  main
  feature
D
* feature
  main
Attempts:
2 left
💡 Hint

The asterisk (*) marks the current branch.

🔀 Workflow
advanced
2:00remaining
Understanding branch pointer movement after commit

You create a new branch dev from main. You then make a commit on dev. What happens to the dev branch pointer?

AThe <code>main</code> branch pointer moves forward to the new commit.
BThe <code>dev</code> branch pointer moves forward to the new commit.
CBoth <code>dev</code> and <code>main</code> pointers move to the new commit.
DNeither branch pointer moves; only the working directory changes.
Attempts:
2 left
💡 Hint

Consider which branch you are on when making the commit.

Troubleshoot
advanced
2:00remaining
Why does 'git checkout' fail with 'pathspec' error?

You try to switch to a branch named feature using git checkout feature, but get this error:

error: pathspec 'feature' did not match any file(s) known to git

What is the most likely cause?

AThe branch <code>feature</code> does not exist locally or remotely.
BYou have uncommitted changes blocking the checkout.
CYou are not inside a Git repository.
DThe repository is corrupted and needs repair.
Attempts:
2 left
💡 Hint

Check if the branch exists before switching.

Best Practice
expert
2:00remaining
Why keep branches short-lived and merged frequently?

In Git workflows, why is it recommended to keep branches short-lived and merge them back often?

ATo avoid using tags for releases.
BTo increase the number of branches in the repository.
CTo reduce merge conflicts and keep history clean.
DTo prevent commits from being pushed to remote repositories.
Attempts:
2 left
💡 Hint

Think about teamwork and code integration.