Enhance your understanding of Git rebase and merge commands through practical workflow scenarios. This quiz focuses on the differences, use cases, and effects of rebase versus merge in modern version control, helping you choose the right approach for clean project histories.
Given a scenario where you have completed a feature branch off the main branch, which command should you use if you want to maintain a linear project history without unnecessary merge commits?
Explanation: Using 'git rebase main' will move the feature branch to start from the latest commit of main, applying your feature changes on top to maintain a linear history. 'git merge main' would merge main into your feature with an additional merge commit, branching the history. 'git branch main' is used for creating a branch, not integrating changes. 'git reset main' would alter the current branch's commit pointer, potentially losing changes if misused.
When collaborating with a large team, which method should you use to ensure that the complete history of how changes were integrated, including context about branch structure, is preserved?
Explanation: Merging preserves the full history, including when and how branches were combined, as it creates a merge commit and keeps the branch structure visible. Rebasing rewrites history, potentially making it harder to see when features were developed together. Git squash combines commits, losing granular history, while git stash is unrelated to history management and is used for temporarily saving changes.
If a conflict arises during rebase, what is the recommended workflow to resolve it and continue rebasing your feature branch onto the latest main branch?
Explanation: The correct way to handle a conflict during rebase is to resolve the conflicts, stage the resolved files with git add, and then use git rebase --continue to proceed. Aborting the rebase would result in losing progress on the rebase. Committing directly without continuing the rebase breaks the intended flow. Deleting the branch and restarting is unnecessary and an extreme solution.
Why should rebasing be avoided for branches that have already been shared with others in a central repository?
Explanation: Rebasing changes the commit history, which can cause synchronization issues if others are working on the same branch, leading to conflicts. Merging does not result in data loss, but adds a merge commit. Rebasing does not affect repository size in any significant way, nor does it delete your branch.
Before opening a pull request, which method should you use if your goal is to present a clear and linear commit history for your feature branch without clutter from previous merges?
Explanation: Rebasing your branch onto main results in a straight, linear history, which is desirable for clear pull requests. Merging the branch into main adds merge commits and can clutter the history. Cherry-picking all commits is inefficient and error-prone. Cloning the repository again is unrelated to history management or preparing for a pull request.