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.
Which Git command is used to create a new branch called 'feature1' without switching to it immediately?
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.
After creating a branch named 'development', what is the correct command to switch to it?
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.
What typically causes a merge conflict when merging two branches in Git?
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.
In which scenario does a 'fast-forward' merge occur in Git?
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.
Which command creates a local branch called 'feature' tracking a remote branch of the same name?
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.
When should you prefer 'git rebase' over 'git merge' to integrate feature branch changes?
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.
After merging, which command deletes a local branch called '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.
What does 'origin/master' typically refer to in Git terminology?
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.'
Which of the following is a recommended naming convention for feature branches?
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.
Which command shows the name of the branch you are currently working on?
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.