Essential Branching and Merging Strategies in Git Quiz

Explore foundational concepts and best practices of branching and merging strategies in Git, including workflows, conflict resolution, and branch types. Perfect for beginners seeking to understand how to manage collaborative development with Git's core features.

  1. Understanding Branches

    In Git, what is the primary purpose of creating branches during software development?

    1. To reduce the number of git commands needed
    2. To work on new features or bug fixes without affecting the main codebase
    3. To permanently delete unused files
    4. To increase the speed of file transfers

    Explanation: Creating branches allows developers to make changes for new features or bug fixes in isolation from the main codebase, ensuring stability. Deleting unused files is not a function of branching, nor does branching directly relate to file transfer speed. The number of commands required does not decrease due to branching, as each branch often requires its own operations.

  2. Basic Merging

    Suppose two developers work on separate branches and want to bring their changes together. Which Git operation should they use?

    1. git merge
    2. git remove
    3. git duplicate
    4. git pull-request

    Explanation: The 'git merge' command combines changes from different branches into one, allowing collaborative development. 'git remove' deletes files, not merges branches. 'git pull-request' is not a standard git operation, and 'git duplicate' does not exist in Git for merging purposes.

  3. Feature Branching Workflow

    Which branching strategy suggests creating a new branch for each new feature or fix being developed?

    1. Single-branch workflow
    2. Feature branching
    3. Detached HEAD state
    4. Linear commit flow

    Explanation: Feature branching involves creating a separate branch for every new feature or fix, which makes parallel development and later integration easier. The single-branch workflow uses only the main branch for all changes. Linear commit flow refers to a development process without branching, and detached HEAD state is a situation where HEAD points to a commit, not a branch.

  4. Fast-Forward Merge

    If a branch can be merged into another without any divergent changes, what type of merge occurs by default in Git?

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

    Explanation: A fast-forward merge occurs when there are no divergent changes in target and source branches; Git simply moves the pointer forward. Squash merge combines all changes in a branch into a single commit. Octopus merge is for merging more than two branches, and reverse merge is not a standard term in Git.

  5. Resolving Merge Conflicts

    What must a developer do when a merge conflict occurs during a Git merge?

    1. Delete the repository
    2. Shut down their computer to fix it automatically
    3. Manually edit the conflicted files to resolve the conflict
    4. Ignore the conflict message and push anyway

    Explanation: Merge conflicts require manual intervention; the developer must edit the affected files, resolve differences, and complete the merge. Shutting down the computer or ignoring the conflict will not solve the problem, and deleting the repository is unnecessary and counterproductive.

  6. The Purpose of Main/Master Branch

    In most Git repositories, what is the typical role of the main (or master) branch?

    1. It is only used for experimental changes
    2. It cannot be merged into other branches
    3. It serves as the primary or production-ready codebase
    4. It holds only binary files

    Explanation: The main branch generally holds the stable, production-ready code that is deployed or released. Experimental changes are made on separate branches, binary files can exist anywhere but are not the focus of the main branch, and the main branch can be merged into others as needed.

  7. Rebasing Instead of Merging

    If a developer wants to place their feature branch changes on top of the latest main branch commits, which Git operation can achieve this?

    1. git remove
    2. git stash
    3. git restore
    4. git rebase

    Explanation: The 'git rebase' command reruns commits from the feature branch onto the latest base branch, creating a linear history. 'git remove' deletes files, 'git stash' temporarily shelves changes, and 'git restore' reverts files back to a previous state, none of which relate to rebasing.

  8. Naming Branches

    Which branch name is considered descriptive and appropriate when adding a login form to an app?

    1. newbranch
    2. temp
    3. feature/login-form
    4. asdf123

    Explanation: Naming branches like 'feature/login-form' makes it clear what change is being made. Names such as 'asdf123', 'temp', and 'newbranch' are unclear and unhelpful for understanding the branch purpose.

  9. Hotfix Branch Usage

    When a critical bug is found in production, which type of branch is typically created to address it quickly?

    1. Fork branch
    2. Hotfix branch
    3. Develop branch
    4. Release branch

    Explanation: A hotfix branch is created for urgent bugs in production, allowing the fix to be prioritized and later merged back into main. A develop branch is used for ongoing changes, a release branch readies for deployment, and fork branch is not a standard Git term.

  10. Purpose of Merge Commits

    Why does Git sometimes create a separate merge commit when merging branches?

    1. To delete the branch being merged
    2. To record the combined history of multiple branches
    3. To hide changes from contributors
    4. To decrease the repository size

    Explanation: A merge commit is created when histories have diverged, capturing the union of changes and maintaining a clear project history. It does not delete branches, reduce repository size, or obscure changes from others.