Git Branching, Merging, and Conflict Resolution Quiz Quiz

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.

  1. Purpose of Branching

    What is the main reason developers create branches in a Git repository during a project?

    1. To reset the main branch history
    2. To increase file size
    3. To work on features or fixes independently
    4. To delete old code permanently

    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.

  2. Basic Branch Creation

    Which command should you use to create and switch to a new branch named 'feature1' in Git?

    1. git checkout -b feature1
    2. git merge feature1
    3. git start feature1
    4. git branch checkout feature1

    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.

  3. Merging Branches

    Suppose you finished work on a 'feature2' branch. What is the correct command sequence to merge 'feature2' into 'main'?

    1. git checkout main, git merge feature2
    2. git fetch feature2 into main
    3. git merge main into feature2
    4. git branch main feature2

    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.

  4. Fast-Forward Merge

    If no new commits exist on 'main' since branching off 'feature3', what kind of merge will Git perform when merging 'feature3'?

    1. Fast-forward merge
    2. Rebase merge
    3. Octopus merge
    4. Squash merge

    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.

  5. Identifying Merge Conflicts

    Which situation is most likely to cause a merge conflict in Git?

    1. Branches edit different files
    2. One branch is empty
    3. A file is only renamed, not changed
    4. Two branches modify the same line in a file

    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.

  6. Conflict Resolution

    After a merge conflict occurs, where should you look in a file to find and fix the conflicting changes?

    1. At the start of the file
    2. Between special conflict markers
    3. In the commit message
    4. Inside the .gitignore file

    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.

  7. Checking Local Branches

    Which command lists all branches currently available in your local Git repository?

    1. git show
    2. git branch
    3. git remotes
    4. git commit

    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.

  8. Aborting a Merge

    If you want to cancel an in-progress merge after encountering conflicts, what Git command would you use?

    1. git remove --merge
    2. git cancel --conflict
    3. git merge --abort
    4. git stop merge

    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.

  9. Deleting a Branch

    How do you delete a local Git branch named 'old-feature' after merging it?

    1. git delete old-feature
    2. git merge -d old-feature
    3. git branch -d old-feature
    4. git remove old-feature

    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.

  10. Common Merge Strategy for Feature Branches

    Which merge strategy is most commonly used for integrating feature branches into a shared branch like 'main'?

    1. Deleting and recreating main
    2. Cherry-picking every commit individually
    3. Regular merge commit
    4. Force-push without review

    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.