Explore the essentials of version control with this quiz focused on Git branching, merging techniques, and effective conflict resolution strategies. Enhance your understanding of best practices and common workflows in collaborative software development using version control systems.
What is the main reason developers create branches in a Git repository during a project?
Explanation: Creating branches allows developers to work on new features or bug fixes without affecting the main codebase, enabling parallel development. Deleting old code permanently is not the purpose of branching; that's done using removal commands. Increasing file size is not related to branching, and resetting main branch history is a separate advanced operation.
Which command should you use to create and switch to a new branch named 'feature1' in Git?
Explanation: The 'git checkout -b feature1' command creates a new branch named 'feature1' and switches to it immediately. Using 'git merge feature1' attempts to merge an existing branch named 'feature1'. 'git branch checkout feature1' is not a valid command, and 'git start feature1' is incorrect syntax in Git.
Suppose you finished work on a 'feature2' branch. What is the correct command sequence to merge 'feature2' into 'main'?
Explanation: To merge 'feature2' into 'main', first switch to 'main' with 'git checkout main', then run 'git merge feature2'. 'git merge main into feature2' reverses the intended direction, while 'git branch main feature2' is used to create branches, not merge. 'git fetch feature2 into main' is not a merging command.
If no new commits exist on 'main' since branching off 'feature3', what kind of merge will Git perform when merging 'feature3'?
Explanation: When there are no new commits on the receiving branch, Git performs a fast-forward merge, moving the branch pointer ahead. Octopus merge is used for multiple branches at once, not typical for such a case. Rebase merges rewrite history and are a different process. Squash merges combine all changes into a single commit during the merge.
Which situation is most likely to cause a merge conflict in Git?
Explanation: A merge conflict happens when multiple branches modify the same line or section of a file, as Git cannot automatically resolve which changes to keep. Changing different files on separate branches usually doesn't create conflicts. An empty branch cannot cause conflicts. Renaming a file without making changes typically does not result in a conflict.
After a merge conflict occurs, where should you look in a file to find and fix the conflicting changes?
Explanation: Git marks conflicting changes between special markers (e.g., u003Cu003Cu003Cu003Cu003Cu003Cu003C, =======, u003Eu003Eu003Eu003Eu003Eu003Eu003E) inside the affected file. The start of the file may not contain the conflict, and commit messages are for describing changes, not resolving them. The .gitignore file is unrelated to conflict resolution.
Which command lists all branches currently available in your local Git repository?
Explanation: The 'git branch' command displays all branches in your local repository. 'git show' provides details about specific commits. 'git commit' is used to save changes, not list branches. 'git remotes' shows remote repositories, not branches.
If you want to cancel an in-progress merge after encountering conflicts, what Git command would you use?
Explanation: 'git merge --abort' stops the merge process and reverts to the pre-merge state. There is no 'git remove --merge' or 'git stop merge' command in Git, making them incorrect. 'git cancel --conflict' is not a valid Git syntax.
How do you delete a local Git branch named 'old-feature' after merging it?
Explanation: 'git branch -d old-feature' deletes a local branch after ensuring it's been merged. 'git merge -d old-feature' uses incorrect syntax. 'git delete old-feature' and 'git remove old-feature' are not recognized commands for branch deletion in Git.
Which merge strategy is most commonly used for integrating feature branches into a shared branch like 'main'?
Explanation: A regular merge commit records both branches' histories and is the most common and recommended approach for bringing feature branches into a shared branch. Force-pushing is risky and can overwrite others' work. Deleting and recreating the main branch is not a standard method and is disruptive. Cherry-picking each commit is unnecessarily complex for most feature integrations.