Think You Know Git? quiz

Loading quiz...

Never Miss a Quiz!

Get new programming challenges delivered weekly.

TL;DR answer sheet

Think You Know Git? — quiz answer sheet, click to expand.

1. Git and GitHub are the same thing.

Answer: false

Explanation: Git is a version control system, while GitHub is a platform that hosts Git repositories.

2. You made a typo in the commit message in your local repo, how can you fix it?

Answer: git commit --amend

Explanation: The 'git commit --amend' command allows you to modify the most recent commit, including changing the commit message.

3. What does this command allow you to do: git add -p

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.

4. What does this command do: git switch --detach HEAD^^^

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.

5. Which of the following files is not officially recognized by Git?

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.

6. what does this .gitignore pattern do? *.sw[op]

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.

7. What does this command do? git switch -

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.

8. You have uncommitted changes and need to switch branches. What command can you use?

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>'.

9. What's the difference between git stash pop and git stash apply?

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.

10. Can you create two worktrees pointing to the same branch?

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.

11. When does a fast-forward merge occur?

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.