Git Branch Management Essentials Quiz Quiz

Explore fundamental concepts of git branch management, including branching strategies, merging, conflict resolution, and best practices. This quiz helps reinforce key skills for effective version control in collaborative development workflows.

  1. Branch Creation Command

    Which command should you use to create a new branch called 'featureX' from your current branch in git?

    1. git branch featureX
    2. git checkout featureX
    3. git clone featureX
    4. git start featureX

    Explanation: The 'git branch featureX' command creates a new branch named 'featureX' without switching to it. 'git checkout featureX' tries to switch to an existing branch, not create one. 'git clone featureX' is used for cloning repositories, not branches. 'git start featureX' is not a valid git command. Only the correct answer successfully adds a new branch to the repository.

  2. Switching Branches Safely

    You are currently working on 'main' with uncommitted changes and want to switch to 'bugfix'. What is the safest way to do this in git?

    1. Commit or stash your changes before switching branches
    2. Use git fetch to switch branches
    3. Delete the main branch before switching
    4. Run git merge bugfix

    Explanation: Committing or stashing your changes ensures you don't lose work or cause conflicts when switching branches. Git fetch updates remote tracking branches but does not switch your current branch. Deleting 'main' risks losing important data and isn’t necessary for branch switches. Running 'git merge bugfix' attempts a merge, not a branch switch.

  3. Understanding Merge Conflicts

    What is the most likely reason for encountering a merge conflict when merging one branch into another in git?

    1. Both branches modified the same lines in the same file
    2. The branches have no common history
    3. You used git commit instead of git merge
    4. The branches have different names

    Explanation: A merge conflict typically happens when the same lines in a file are changed differently on both branches. No common history may prevent merging entirely rather than causing a conflict. Using 'git commit' alone cannot cause a conflict, and branch naming does not cause conflicts—content changes do.

  4. Deleting a Local Branch

    After finishing work, which command properly deletes a local branch named 'old-feature' in git?

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

    Explanation: The correct command to delete a local branch is 'git branch -d old-feature'. 'git remove branch old-feature', 'git discard old-feature', and 'git delete-branch old-feature' are not valid git commands and will result in errors. Always use the documented branch deletion option.

  5. Purpose of Branch Merging

    What is the main purpose of merging a feature branch into the main branch in git?

    1. To integrate new changes from the feature branch into the main development line
    2. To clone the repository
    3. To permanently delete the feature branch
    4. To reset the repository to an earlier commit

    Explanation: Merging a feature branch into the main branch incorporates completed work into the primary development stream. Cloning a repository is unrelated to merging. Deleting a branch is a separate action performed after merging if desired. Resetting the repository is used for rewinding history and not related to merging feature branches.