A developer is using Git for version control. After creating a new feature branch 'feature-login' from 'main', they make several commits. Meanwhile, another developer has merged changes into 'main'. The developer wants to incorporate the latest main changes into 'feature-login' without creating a merge commit. Which Git command should they use?
Trap 1: git rebase main
`git rebase main` replays feature-login's commits onto main's tip, rewriting their hashes and producing linear history with no merge commit. It is tempting because it is the standard way to integrate upstream changes cleanly, and it would be correct if the branch were private and unpushed.
Trap 2: git merge main
Merge creates a merge commit, which is not desired here.
Trap 3: git checkout main && git pull && git checkout feature-login && git…
The final `git merge main` still produces a merge commit, so the sequence fails the stated requirement despite updating main first. It is tempting because pulling main before merging avoids working from a stale local main, and it would suit a workflow that accepts merge commits.
- A
git rebase main
Why it fails: `git rebase main` replays feature-login's commits onto main's tip, rewriting their hashes and producing linear history with no merge commit. It is tempting because it is the standard way to integrate upstream changes cleanly, and it would be correct if the branch were private and unpushed.
- B
git merge main
Why it fails: Merge creates a merge commit, which is not desired here.
- C
git pull --rebase origin main
git pull --rebase fetches main's commits then replays the branch's local commits on top, producing linear history without a merge commit. This satisfies the stem's requirement to incorporate the latest main changes while avoiding an extra merge commit.
- D
git checkout main && git pull && git checkout feature-login && git merge main
Why it fails: The final `git merge main` still produces a merge commit, so the sequence fails the stated requirement despite updating main first. It is tempting because pulling main before merging avoids working from a stale local main, and it would suit a workflow that accepts merge commits.