200-901 Question 19
Single answerYou are working on a feature branch in a Git repository and want to integrate the latest changes from the main branch into your feature branch. Which command(s) should you use to achieve this while preserving the commit history of both branches?
- A
git merge main
- B
git rebase main
- C
git checkout main
- D
git commit -m 'Merge main into feature'
Show answer and explanation
Correct answer: A
Explanation
To integrate changes from the main branch into a feature branch while preserving the commit history of both branches, the 'git merge main' command is used. This command performs a three-way merge, combining the histories of both branches without rewriting their commits. Other options, such as 'git rebase main,' rewrite the commit history and may not be suitable depending on the workflow requirements, while the other commands do not achieve the desired integration.
- A. Correct.
This is the correct command to merge the main branch into your current feature branch, preserving the commit history of both branches.
- B. Incorrect.
While this command can integrate changes from the main branch, it rewrites the commit history by applying commits from the feature branch on top of the main branch, which does not preserve the original commit order.
- C. Incorrect.
This command switches to the main branch, but it does not integrate changes into your feature branch.
- D. Incorrect.
This is not a valid Git command for merging or rebasing branches. It is used to create a new commit with a specified message.