Git Essentials: Branching, Merging, and Conflict Resolution Quiz Quiz

Explore key concepts in version control with Git through beginner-friendly questions focusing on branching, merging, and resolving conflicts. This quiz helps reinforce understanding of fundamental Git commands and workflows essential for collaborative development.

  1. Branch Creation

    Which Git command creates a new branch called 'feature' from your current branch?

    1. git add branch feature
    2. git create branch feature
    3. git branch feature
    4. git checkout feature

    Explanation: The correct command is 'git branch feature', which creates a new branch named 'feature'. 'git create branch feature' is not a valid command as 'create' is not a recognized subcommand. 'git checkout feature' switches to the branch instead of creating it, unless combined with '-b'. 'git add branch feature' incorrectly uses the 'add' command, which is for staging changes, not branches.

  2. Switching Branches

    To move from your current branch to one called 'develop', which command would you use?

    1. git move develop
    2. git switch develop
    3. git branch develop
    4. git add develop

    Explanation: The command 'git switch develop' switches you to the 'develop' branch if it already exists. 'git branch develop' would create a new branch instead of switching. 'git move develop' is not a valid command in Git. 'git add develop' is used for staging files, not for branch operations.

  3. Merging Branches

    If you want to merge the branch 'feature' into your current branch, which command should you use?

    1. git combine feature
    2. git branch merge feature
    3. git insert feature
    4. git merge feature

    Explanation: 'git merge feature' merges the specified 'feature' branch into the branch you are currently on. 'git branch merge feature' is not an existing Git command structure. 'git combine feature' and 'git insert feature' are not valid Git commands for merging branches.

  4. Viewing Branches

    Which command displays a list of all local branches in your repository?

    1. git check branches
    2. git branch
    3. git show branch
    4. git view branch

    Explanation: 'git branch' lists all local branches in your repository. 'git check branches' and 'git view branch' are not recognized commands. 'git show branch' is similar but used for comparing branches rather than simply listing them.

  5. Fast-forward Merges

    What is a 'fast-forward' merge in Git?

    1. When the target branch pointer simply moves forward to the merged branch's latest commit
    2. When changes are combined into a new, separate merge commit
    3. When both branches have diverged with conflicting changes
    4. When only deleted files are merged

    Explanation: A 'fast-forward' merge occurs when the target branch has not diverged and can simply be moved ahead to the incoming branch's commit. If both branches have diverged or contain conflicting changes, a true merge commit is needed. Creating a new, separate merge commit is not required in a fast-forward merge. The scenario about merging only deleted files is unrelated to fast-forward merges.

  6. Identifying Conflicts

    When a merge conflict occurs, how does Git indicate the conflicting parts in a file?

    1. By adding special markers like u003Cu003Cu003Cu003Cu003Cu003Cu003C, =======, and u003Eu003Eu003Eu003Eu003Eu003Eu003E
    2. By deleting the conflicting lines automatically
    3. By moving the conflicting file to a separate folder
    4. By changing the file's extension to .conflict

    Explanation: Git adds conflict markers such as u003Cu003Cu003Cu003Cu003Cu003Cu003C, =======, and u003Eu003Eu003Eu003Eu003Eu003Eu003E to indicate conflicting content inside files. Git does not move the files to a different folder or delete content automatically; resolving the conflict requires manual intervention. Renaming the file's extension is not something Git performs during conflicts.

  7. Conflict Resolution

    After manually fixing a merge conflict in a file, which command stages the resolved file?

    1. git add filename
    2. git resolve filename
    3. git fix filename
    4. git update filename

    Explanation: Once you have resolved a conflict, you use 'git add filename' to stage the fixed file. 'git resolve filename' and 'git fix filename' are not standard Git commands for this purpose. 'git update filename' does not stage resolved files either.

  8. Branch Deletion

    Suppose you want to delete a branch named 'old-feature' locally. Which command should you run?

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

    Explanation: 'git branch -d old-feature' safely deletes the local branch 'old-feature'. 'git remove branch old-feature' and 'git branch remove old-feature' misuse Git's command syntax. 'git delete old-feature' does not match the actual Git command structure for removing branches.

  9. Branch Naming

    Which of the following is an example of a valid branch name in Git?

    1. feature/login-page
    2. feature login page
    3. feature:login:page
    4. /feature-login-page/

    Explanation: Branch names like 'feature/login-page' are valid and commonly used, using slashes to organize branches. Spaces in 'feature login page' are not allowed in branch names. Leading and trailing slashes, as in '/feature-login-page/', are invalid. Colons, like in 'feature:login:page', may cause issues and are best avoided in branch names.

  10. Undoing Merges

    If you just completed a merge and want to undo it, which command could you use to reset your branch to the previous commit?

    1. git unmerge HEAD
    2. git revert HEAD
    3. git reset --hard HEAD~1
    4. git remove merge

    Explanation: 'git reset --hard HEAD~1' deletes the most recent commit, including a completed merge, and moves your branch pointer backwards. 'git revert HEAD' creates a new commit that undoes the changes rather than removing the commit. 'git remove merge' and 'git unmerge HEAD' are not valid Git commands for undoing a merge.