🌍 Git & Version Control · subject
Git & Version Control Branching and Merging Syllabus
The Branching and Merging syllabus for Git & Version Control in full: 6 chapters and 25 topics, every one listed below, plus 54 Branching and Merging flashcards with answers.
Branching and Merging syllabus: all 6 chapters
Expand any chapter to see its topics and sub-topics.
-
Branch Fundamentals
4 topics- What a Branch Really Is
- Creating and Switching Branches
- Listing, Renaming, and Deleting Branches
- Tracking and Upstream Branches
-
Merging Branches
4 topics- Fast-Forward Merges
- Three-Way Merges
- Squash Merges
- Aborting and Continuing Merges
-
Resolving Merge Conflicts
4 topics- Understanding Conflict Markers
- Manual Conflict Resolution
- Using Merge Tools
- Strategies to Avoid Conflicts
-
Rebasing
4 topics- Rebase vs Merge
- Interactive Rebase
- The Golden Rule of Rebasing
- Resolving Conflicts During Rebase
-
Tagging and Releases
4 topics- Lightweight vs Annotated Tags
- Creating and Pushing Tags
- Semantic Versioning
- Checking Out and Deleting Tags
-
Branching Strategies
5 topics- Git Flow
- GitHub Flow
- GitLab Flow
- Trunk-Based Development
- Release and Hotfix Branches
Git & Version Control Branching and Merging flashcards — 54 questions with answers
What is a Git branch, technically?
A lightweight, movable pointer (a reference) to a specific commit. Because a commit records its parent(s), the branch pointer plus the commit history defines the whole line of development.
Where does Git store the current branch pointer, and what file typically references it?
Branch refs are stored under .git/refs/heads/ (or packed-refs). The special file .git/HEAD points to the current branch, usually as a symbolic ref like 'ref: refs/heads/main'.
What does HEAD normally point to, and what is a 'detached HEAD'?
HEAD normally points to the current branch (a symbolic reference). A detached HEAD occurs when HEAD points directly to a commit instead of a branch, so new commits are not recorded on any branch.
Why is creating a branch in Git so cheap compared to older VCSs?
A branch is just a 41-byte file containing a commit SHA-1 (plus newline). Git does not copy files; it only writes a new pointer, making branch creation nearly instantaneous.
Which command creates a new branch without switching to it?
git branch <name>. It creates a pointer at the current commit but leaves HEAD on the current branch.
What is the modern command to create and switch to a new branch in one step (and the older equivalent)?
Modern: git switch -c <name>. Older/equivalent: git checkout -b <name>.
How do you create a new branch starting from a specific commit or another branch?
git branch <name> <start-point> or git switch -c <name> <start-point>, where start-point is a commit SHA, tag, or branch name.
What is the purpose-built command to switch branches introduced to reduce checkout's ambiguity?
git switch <branch>. It only changes branches (unlike git checkout, which also restores files), making intent clearer and safer.
How do you list all local branches, and how is the current branch marked?
git branch. The current branch is marked with an asterisk (*) and often highlighted in color.
Which flag lists remote-tracking branches, and which lists both local and remote?
git branch -r lists remote-tracking branches; git branch -a lists both local and remote-tracking branches.
How do you rename the current branch, and how do you rename a different branch?
Current: git branch -m <newname>. Another branch: git branch -m <oldname> <newname>. (-M forces the rename over an existing name.)
What is the difference between git branch -d and git branch -D?
-d deletes a branch only if it is already merged (safe delete). -D forces deletion even if unmerged, discarding those commits' reachability.
Which flag shows the last commit on each branch when listing?
git branch -v (verbose) shows the SHA and subject of each branch's tip commit; -vv also shows upstream tracking info.
What is a tracking (upstream) branch?
A local branch configured to have a direct relationship with a remote-tracking branch (its upstream). It lets commands like git pull, git push, and git status compare against the remote without naming it explicitly.
How do you set the upstream for the current branch to origin/main?
git branch --set-upstream-to=origin/main, or when pushing: git push -u origin <branch> (the -u/--set-upstream flag).
In 'git status', what does 'Your branch is ahead of origin/main by 2 commits' mean?
Your local branch has 2 commits that the upstream (origin/main) does not yet have; you would need to push to share them.
What is the difference between a remote-tracking branch (e.g. origin/main) and a local tracking branch?
A remote-tracking branch (origin/main) is a read-only local snapshot of the remote's state, updated by fetch. A local tracking branch (main) is your editable branch configured to track that remote-tracking branch.
What is a fast-forward merge?
A merge where the target branch's tip is a direct ancestor of the branch being merged, so Git simply moves the branch pointer forward to the incoming tip. No new merge commit is created.
Under what condition is a fast-forward merge NOT possible?
When the two branches have diverged, i.e., the current branch has commits not on the incoming branch. Their histories are not linear, so Git must perform a three-way merge.
How do you force a merge commit even when a fast-forward is possible?
git merge --no-ff <branch>. This always creates a merge commit, preserving the fact that a branch existed.
Show the other 34 Branching and Merging flashcards
What does git merge --ff-only do?
It performs the merge only if it can be done as a fast-forward; otherwise it aborts with an error instead of creating a merge commit.
What is a three-way merge?
A merge that uses three commits: the two branch tips and their common ancestor (merge base). Git compares each side against the base to combine changes and creates a new merge commit with two parents.
What is the 'merge base' in a three-way merge?
The best common ancestor commit of the two branches being merged. It serves as the reference point for determining what changed on each side. You can find it with git merge-base A B.
How many parents does a merge commit created by a three-way merge have?
Two parents: the tip of the branch you were on (first parent) and the tip of the branch you merged in (second parent).
What is a squash merge, and what command performs it?
git merge --squash <branch>. It combines all changes from the branch into your working tree/index as a single set of staged changes, which you then commit as one commit. No merge commit and no second parent are recorded.
How does a squash merge affect branch history compared to a regular merge?
A squash merge produces a single new commit with no link (parent) to the merged branch, so the branch's individual commits and merge relationship are not preserved in history.
After 'git merge --squash <branch>', why must you run git commit manually?
Because --squash stages the combined changes but deliberately does not create the commit, letting you write a single consolidated commit message.
How do you abort a merge that has stopped due to conflicts?
git merge --abort. It restores the working tree and index to the state before the merge began (equivalent to resetting to MERGE_HEAD's pre-merge state).
After resolving conflicts, how do you complete/continue a merge?
Stage the resolved files with git add, then run git commit (or git merge --continue) to create the merge commit.
What does the file .git/MERGE_HEAD indicate during a merge?
It records the commit(s) being merged in and signals that a merge is in progress. Its presence lets Git know the next commit should be a merge commit and enables git merge --abort.
What do the conflict markers <<<<<<<, =======, and >>>>>>> delimit?
<<<<<<< marks the start of your current branch's version (ours), ======= separates the two versions, and >>>>>>> marks the end of the incoming branch's version (theirs).
In a conflict block, which side appears above the ======= line and which appears below?
Above =======: the current branch's content (labeled HEAD / 'ours'). Below =======: the incoming branch's content ('theirs'), ending at >>>>>>> with the branch/commit name.
What is the diff3 conflict style and what extra information does it add?
The diff3 style (git config merge.conflictstyle diff3) adds a third section marked ||||||| showing the original common-ancestor (base) content, so you can see what both sides changed from.
What are the manual steps to resolve a merge conflict?
1) Open each conflicted file. 2) Edit to keep the desired content and remove all conflict markers. 3) git add the file to mark it resolved. 4) git commit to finish the merge.
How do you list which files are currently conflicted?
git status shows them under 'Unmerged paths'. You can also use git diff --name-only --diff-filter=U to list only conflicted files.
During a conflict, what do 'git checkout --ours <file>' and '--theirs <file>' do?
They resolve the file by taking one entire side: --ours keeps the current branch's version, --theirs keeps the incoming branch's version, discarding the other side's changes for that file.
What command launches a configured graphical merge tool to resolve conflicts?
git mergetool. It opens the tool set in the merge.tool config (e.g., meld, kdiff3, vimdiff) for each conflicted file.
In a typical three-pane merge tool, what do LOCAL, REMOTE, and BASE represent?
LOCAL = your current branch's version (ours), REMOTE = the incoming branch's version (theirs), BASE = the common ancestor. The center/output pane is the merged result you produce.
How do you configure a default merge tool?
git config --global merge.tool <toolname> (e.g., meld). You can also set mergetool.<tool>.path if the executable is not on PATH.
Name three practical strategies to avoid merge conflicts.
1) Pull/rebase from the shared branch frequently to stay current. 2) Keep branches short-lived and changes small/focused. 3) Coordinate so team members avoid editing the same lines/files, and use consistent formatting to reduce spurious conflicts.
How does frequently integrating (small, frequent merges/pulls) reduce conflicts?
It keeps divergence small, so each merge reconciles fewer differences. Long-lived branches accumulate many changes that overlap, dramatically raising conflict likelihood and difficulty.
What is the fundamental difference between merge and rebase?
Merge combines two histories by creating a new merge commit, preserving the actual branching structure. Rebase replays your commits on top of another base commit, creating new commits and producing a linear history.
Does rebase modify existing commits, and what does that imply about their SHAs?
Rebase creates new commits with new SHA-1 hashes (rewriting history), even if the content is identical, because a commit's hash depends on its parent and metadata. The originals become unreferenced.
When is merge preferred over rebase, and vice versa?
Merge is preferred for integrating shared/public branches and preserving true history. Rebase is preferred for cleaning up local commits before sharing and for keeping a linear, readable history on private branches.
What command starts an interactive rebase over the last 3 commits?
git rebase -i HEAD~3. It opens an editor with a to-do list of those commits to reorder, edit, squash, or drop.
Name the common interactive rebase actions (todo commands) and their effects.
pick (keep commit), reword (change message), edit (pause to amend), squash (combine into previous, keep both messages), fixup (combine into previous, discard its message), drop (remove commit).
What is the difference between 'squash' and 'fixup' in interactive rebase?
Both merge a commit into the preceding one. squash lets you combine and edit both commit messages; fixup discards the squashed commit's message, keeping only the previous one's.
State the Golden Rule of Rebasing.
Never rebase commits that have been pushed to a shared/public branch that others may have based work on. Rebasing rewrites history and forces collaborators into painful re-syncs.
Why does violating the Golden Rule of Rebasing cause problems for collaborators?
Rebasing replaces shared commits with new ones (different SHAs). Others still have the old commits, so their histories diverge, producing duplicate commits and confusing merges when they pull.
How do you resolve conflicts during a rebase and continue?
Edit and stage the conflicted files with git add, then run git rebase --continue. Use git rebase --skip to drop the current commit, or git rebase --abort to cancel and restore the original branch.
During a rebase conflict, what do 'ours' and 'theirs' refer to (and why is it counterintuitive)?
In rebase, 'ours' is the branch you are rebasing onto (the new base), and 'theirs' is your commit being replayed. This is reversed from merge because rebase applies your commits on top of the base.
What is the difference between a lightweight tag and an annotated tag?
A lightweight tag is just a name pointing to a commit (like a fixed branch). An annotated tag is a full object stored in the database with tagger name, email, date, message, and optional GPG signature.
How do you create a lightweight tag versus an annotated tag?
Lightweight: git tag <name>. Annotated: git tag -a <name> -m "message" (or -s for a signed tag). Annotated is recommended for releases.
By default, does git push send tags to the remote, and how do you push them?
No. Tags are not pushed automatically. Push one with git push origin <tagname>, or push all tags with git push origin --tags (use --follow-tags to push annotated tags reachable from pushed commits).
Git & Version Control Branching and Merging FAQ
What is in the Git & Version Control Branching and Merging syllabus?
Git & Version Control Branching and Merging is split into 6 chapters: Branch Fundamentals, Merging Branches, Resolving Merge Conflicts, Rebasing, Tagging and Releases and Branching Strategies. Together they contain 25 topics.
How many chapters are in Git & Version Control Branching and Merging?
6 chapters, containing 25 topics. The largest chapter is Branching Strategies, with 5 topics.
Are there flashcards for Git & Version Control Branching and Merging?
Yes — a 54-card Branching and Merging deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.