When you need another developer's in-progress work while on your own feature branch, git merge lets you pull their branch's commits directly into yours, combining both sets of changes.
Key Points: • Run git pull first to make sure your local repository and remote-tracking branches are up to date. • Switch to your own feature branch with git checkout before merging anything into it. • git merge <other-branch> combines the other branch's commits into yours, creating a merge commit if histories have diverged. • Resolve any conflicts that arise from overlapping changes before the merge can complete. • For pulling in just a specific commit rather than a whole branch, git cherry-pick is a more targeted alternative.
Example: While building a checkout page that depends on a new pricing API a teammate is writing on branch feature/pricing-api, you run git checkout feature/checkout and then git merge feature/pricing-api to bring their work into yours.
Code Example:
git pull
git checkout feature/checkout
git merge feature/pricing-apiInterview Tip: A concise interview answer is:
"I'd make sure my local repo is up to date with git pull, switch to my feature branch, and run git merge with the name of the other branch to bring those changes in. If there are conflicts, I resolve them before continuing my own work."