In Git, a branch is often described as a pointer. What exactly does this pointer reference?
Think about what Git uses to track changes and history.
A Git branch is a lightweight movable pointer to a commit. It marks a position in the commit history, allowing you to work on different lines of development.
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
The asterisk (*) marks the current branch.
After switching to the feature branch, git branch shows * feature indicating the current branch, and main as another branch.
You create a new branch dev from main. You then make a commit on dev. What happens to the dev branch pointer?
Consider which branch you are on when making the commit.
When you commit on a branch, only that branch's pointer moves forward to the new commit. Other branches remain at their previous commits.
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?
Check if the branch exists before switching.
This error means Git cannot find a branch or file named feature. Usually, the branch does not exist locally or remotely.
In Git workflows, why is it recommended to keep branches short-lived and merge them back often?
Think about teamwork and code integration.
Short-lived branches reduce the chance of conflicts and make it easier to integrate changes, keeping the project history clear and manageable.