Junior — Middle
How can you integrate the latest updates from the main development branch into a separate feature branch in Git?
sobes.tech AI
Answer from AI
To integrate the latest updates from the main branch (e.g., main or master) into a separate feature branch in Git, you can use two main approaches:
- Merge
git checkout feature-branch
git merge main
This method creates a new merge commit, combining changes from main into your branch.
- Rebase
git checkout feature-branch
git rebase main
Rebase "moves" your commits on top of the latest commits from main, creating a more linear history.
The choice between merge and rebase depends on your team's policy and preferences. Merge preserves the branch history, while rebase makes the history cleaner but requires caution when working collaboratively.
Before integrating updates, ensure your local main branch is up to date:
git checkout main
git pull origin main