Git Branching and Merging Workflows Quiz Quiz

Assess your understanding of key concepts in Git branching and merging workflows, including branch creation, merge conflicts, strategies, and workflow best practices. This quiz helps reinforce essential Git terms and scenarios for anyone interested in version control basics.

  1. Creating a New Branch

    Which Git command is used to create a new branch called 'feature1' without switching to it immediately?

    1. git brnch feature1
    2. git checkout feature1
    3. git merge feature1
    4. git branch feature1

    Explanation: The command 'git branch feature1' creates a new branch named 'feature1' without checking it out. 'git checkout feature1' would switch to the branch, but only if it already exists. 'git merge feature1' attempts to merge another branch into the current one, and 'git brnch feature1' is a misspelled command. Only 'git branch feature1' correctly creates the new branch without switching.

  2. Switching Branches

    After creating a branch named 'development', what is the correct command to switch to it?

    1. git merge development
    2. git checkout development
    3. git switch --create development
    4. git switch --delete development

    Explanation: 'git checkout development' is the standard earlier command to switch to an existing branch named 'development.' 'git switch --create development' would attempt to create and switch, but requires the branch not to exist. 'git merge development' would merge rather than switch, and 'git switch --delete development' is not a valid command for switching. Only 'git checkout development' is correct in this context.

  3. Understanding Merge Conflicts

    What typically causes a merge conflict when merging two branches in Git?

    1. Branches have the same commit history.
    2. Neither branch has any commits.
    3. Both branches modify the same lines of a file differently.
    4. The branches each have different names.

    Explanation: A merge conflict generally occurs when the same lines in a file are changed differently on two branches. Simply having different branch names does not cause a conflict. If neither branch has commits, there is nothing to merge, so conflict cannot arise. Having the same commit history means there are no differences, so merging proceeds without conflict.

  4. Fast-Forward Merge

    In which scenario does a 'fast-forward' merge occur in Git?

    1. The feature branch is ahead and the main branch is untouched since the branch was created.
    2. Branches have unresolved merge conflicts.
    3. Both branches have unique commits since branching.
    4. The main branch was deleted before merging.

    Explanation: A fast-forward merge is possible only when the main branch has not moved forward after the feature branch was created. If both branches have unique commits, Git cannot perform a fast-forward merge. Merge conflicts are unrelated to fast-forward merges, and deleting the main branch makes merging impossible. The correct condition is when only the feature branch has advanced.

  5. Tracking Remote Branches

    Which command creates a local branch called 'feature' tracking a remote branch of the same name?

    1. git track feature origin/feature
    2. git start feature
    3. git fetch feature
    4. git checkout -b feature origin/feature

    Explanation: 'git checkout -b feature origin/feature' both creates the local branch and sets it to track the remote branch named 'feature.' 'git fetch feature' only updates the information about the remote branch. 'git start feature' and 'git track feature origin/feature' are not valid Git commands. Only the first option creates a local branch tracking a remote one appropriately.

  6. Rebasing Basics

    When should you prefer 'git rebase' over 'git merge' to integrate feature branch changes?

    1. When deleting branches after merging.
    2. To intentionally create a new merge commit.
    3. To keep a linear project history without unnecessary merge commits.
    4. To roll back to an earlier commit.

    Explanation: 'git rebase' is preferred when you want a linear sequence of commits and wish to avoid additional merge commits. Merging creates a new merge commit, which rebase is designed to avoid. Rebasing is not used for deleting branches or rolling changes back. Only the first option describes the main advantage of rebase over merge.

  7. Deleting a Local Branch

    After merging, which command deletes a local branch called 'hotfix'?

    1. git delete hotfix
    2. git branch -d hotfix
    3. git drop hotfix
    4. git remove branch hotfix

    Explanation: 'git branch -d hotfix' is the correct command to delete a local branch safely after merging. 'git remove branch hotfix', 'git delete hotfix', and 'git drop hotfix' are invalid commands in the context of Git. Only 'git branch -d' properly removes the specified branch if it has been merged.

  8. Understanding 'origin/master'

    What does 'origin/master' typically refer to in Git terminology?

    1. A tag for tracking deleted files.
    2. A temporary staging area.
    3. A script that manages branches.
    4. The main branch on the default remote repository.

    Explanation: 'origin/master' is the shorthand for the main branch on the default remote, commonly called 'origin.' It does not refer to tags, scripts, or temporary staging areas in Git context. Only the main branch on the remote repository fits the description of 'origin/master.'

  9. Branch Naming Best Practices

    Which of the following is a recommended naming convention for feature branches?

    1. update
    2. temp
    3. main
    4. feature/short-description

    Explanation: Using 'feature/short-description' clearly specifies that the branch is for a new feature and describes its purpose. 'main' is typically reserved for the primary branch, and 'temp' or 'update' do not communicate specific intent or context. Only the first option follows standard descriptive naming conventions for features.

  10. Checking Current Branch

    Which command shows the name of the branch you are currently working on?

    1. git fetch
    2. git branch
    3. git commit
    4. git push

    Explanation: Running 'git branch' will display a list of all local branches, highlighting the current one with an asterisk. 'git commit' saves tracked changes, 'git fetch' fetches updates from remote, and 'git push' uploads local changes. Only 'git branch' reveals your present working branch.