Git Git Branching and Merging 2 — Questions and Answers
Question 1: What is the purpose of `git merge --squash`?
- Combines all commits from a branch into one staged change without committing (Correct answer)
- Deletes all commits on the branch
- Forces a fast-forward merge
- Merges only the last commit
Correct answer: Combines all commits from a branch into one staged change without committing
The `--squash` option collapses all commits from the source branch into a single staged change that you then commit manually.
Question 2: Which command renames a local branch from `old-name` to `new-name`?
- git branch -m old-name new-name (Correct answer)
- git rename old-name new-name
- git branch --rename old-name new-name
- git checkout -r old-name new-name
Correct answer: git branch -m old-name new-name
The `git branch -m old-name new-name` command renames the specified local branch.
Question 3: What is the 'detached HEAD' state?
- A corrupted repository state
- When HEAD points directly to a commit rather than a branch reference (Correct answer)
- When a branch has no commits
- When remote and local branches are out of sync
Correct answer: When HEAD points directly to a commit rather than a branch reference
Detached HEAD occurs when HEAD points to a specific commit rather than a named branch, usually after checking out a commit directly.
Question 4: Which strategy does `git merge -s octopus` use?
- Merges two branches with conflict resolution
- Merges more than two branches simultaneously (Correct answer)
- Creates an empty merge commit
- Resets both branches to a common ancestor
Correct answer: Merges more than two branches simultaneously
The octopus merge strategy is designed to merge more than two branches at once, ideal for integrating multiple feature branches simultaneously.
Question 5: After resolving merge conflicts, what is the correct next step?
- Run `git merge --continue`
- Stage the resolved files with `git add` then commit (Correct answer)
- Run `git rebase --continue`
- Restart the merge with `git merge --reset`
Correct answer: Stage the resolved files with `git add` then commit
After manually resolving conflicts, you must stage the resolved files with `git add` and then create the merge commit.
Question 6: What does `git branch --merged` display?
- Branches that have been pushed to remote
- Branches whose tips are reachable from the current HEAD (Correct answer)
- All branches with merge commits
- Branches currently checked out
Correct answer: Branches whose tips are reachable from the current HEAD
The `git branch --merged` command lists branches whose latest commits are already reachable from the current HEAD, making them safe to delete.
What is the purpose of `git merge --squash`?