- 3 min read
Think You Know Git? — quiz answer sheet, click to expand.
Answer: false
Explanation: Git is a version control system, while GitHub is a platform that hosts Git repositories.
Answer: git commit --amend
Explanation: The 'git commit --amend' command allows you to modify the most recent commit, including changing the commit message.
Answer: Select specific hunks of changes to stage
Explanation: The git add -p command allows you to interactively review and select specific hunks of changes in your files to stage for the next commit.
Answer: Detaches HEAD and moves it three commits back
Explanation: HEAD^^^ is the same as HEAD~3, which refers to the commit three steps before the current HEAD. The command detaches HEAD and points it to that commit.
Answer: .gitkeep
Explanation: The .gitkeep file is not an official Git file; it's a convention used by developers to include empty directories in a Git repository, as Git does not track empty directories.
Answer: Ignores files with .swo and .swp
Explanation: The pattern *.sw[op] uses a character class [op] to match either 'o' or 'p', so it ignores files with the extensions .swo and .swp.
Answer: Switches to the previous branch
Explanation: The git switch - command is a shorthand for switching back to the previous branch you were on, works like cd - in linux.
Answer: git stash or git switch -c <new-branch>
Explanation: You can use 'git stash' to temporarily save your uncommitted changes, allowing you to switch branches without losing your work. or you can create a new branch with your uncommitted changes using 'git switch -c <new-branch>'.
Answer: Pop removes the stash after applying, apply keeps it
Explanation: pop applies the stash and then removes it from the stash stack, while apply applies the stash but keeps it in the stash stack for future use.
Answer: Yes, but you must use the --force flag
Explanation: By default, Git prevents multiple worktrees from checking out the same branch to avoid confusion. However, you can override this behavior using the --force flag with git worktree add, which allows multiple worktrees to point to the same branch.
Answer: When the target branch is an ancestor of the source branch
Explanation: A fast-forward merge occurs when the branch being merged into is already an ancestor of the branch being merged. Git simply moves the pointer forward without creating a new merge commit.