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.
Which Git command creates a new branch called 'feature' from your current branch?
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.
To move from your current branch to one called 'develop', which command would you use?
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.
If you want to merge the branch 'feature' into your current branch, which command should you use?
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.
Which command displays a list of all local branches in your repository?
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.
What is a 'fast-forward' merge in Git?
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.
When a merge conflict occurs, how does Git indicate the conflicting parts in a file?
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.
After manually fixing a merge conflict in a file, which command stages the resolved file?
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.
Suppose you want to delete a branch named 'old-feature' locally. Which command should you run?
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.
Which of the following is an example of a valid branch name in Git?
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.
If you just completed a merge and want to undo it, which command could you use to reset your branch to the previous commit?
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.