Git110 exercises

Git Exercises with Answers

Practise Git with 110 interactive exercises: multiple choice, fill-in-the-blank, output prediction and debugging. Every exercise gives instant feedback, a hint and the full solution.

Score0/ 110

1Introduction

Read the lesson
Fill in the blankseasyIntroduction

Complete the command that sets your name for every repository.

git   user.name "Ava Patel"
Multiple choiceeasyIntroduction

What is a commit?

Multiple choicemediumIntroduction

Why can you commit without an internet connection?

Predict the outputeasyIntroduction

What does git --version show if Git is installed?

Multiple choicemediumIntroduction

Which command shows the version of Git you have installed?

2init, add & commit

Read the lesson
Fill in the blankseasyinit, add & commit

Complete the commands to stage every change and commit it.

git  .
git  -m "Add about page"
Multiple choiceeasyinit, add & commit

Which command shows which files are staged, modified or untracked?

Multiple choicemediuminit, add & commit

You changed index.html and style.css but only want to commit style.css. What do you run?

Predict the outputmediuminit, add & commit

You create notes.txt and run git status without adding it. Where is it listed?

Multiple choicemediuminit, add & commit

You changed three files but only want to commit one. What do you do?

3log, diff & .gitignore

Read the lesson
Fill in the blankseasylog, diff & .gitignore

Complete the command to show the history with one line per commit.

git  
Multiple choicemediumlog, diff & .gitignore

Which command shows the changes that will go into your next commit?

Multiple choicemediumlog, diff & .gitignore

Which line in a .gitignore file ignores every file ending in .log?

Predict the outputmediumlog, diff & .gitignore

In git diff output, what does a line starting with + mean?

Multiple choicemediumlog, diff & .gitignore

Which command shows the exact changes made in one commit?

4Moving & Removing Files

Read the lesson
Fill in the blankseasyMoving & Removing Files

Complete the command that renames a file and stages the change.

git  about.htm about.html
Multiple choiceeasyMoving & Removing Files

What does git rm --cached secrets.txt do?

Multiple choicemediumMoving & Removing Files

Which command shows what git clean would delete, without deleting anything?

Predict the outputmediumMoving & Removing Files

What does git status --short show after git mv a.txt b.txt?

Multiple choicehardMoving & Removing Files

Why can't files removed by git clean -f be recovered with Git?

5Config & Aliases

Read the lesson
Fill in the blankseasyConfig & Aliases

Complete the command that sets your global editor to VS Code.

git config  core.editor "code --wait"
Multiple choiceeasyConfig & Aliases

Where are --global settings stored?

Predict the outputmediumConfig & Aliases

Global user.name is "Sam" and the repository's local user.name is "Sam (Work)". What does git config --get user.name print inside that repository?

Fill in the blanksmediumConfig & Aliases

Complete the command that creates an alias git co for git switch.

git config --global  switch
Multiple choicehardConfig & Aliases

Which setting helps when Windows and Mac users edit the same files?

Fill in the blankseasyBranches

Complete the command that creates a branch called about-page and switches to it.

git   about-page
Multiple choiceeasyBranches

How can you tell which branch you're on in git branch output?

Multiple choicemediumBranches

You commit on feature-x, then switch to main. Is the new commit on main?

Predict the outputmediumBranches

What does git branch -d old-idea do if old-idea has commits that were never merged?

Multiple choicemediumBranches

Which command deletes a branch that has already been merged?

7Merging & Conflicts

Read the lesson
Fill in the blankseasyMerging & Conflicts

Complete the commands to bring the search branch into main.

git  main
git  search
Multiple choicemediumMerging & Conflicts

When does Git do a fast-forward merge?

Multiple choicemediumMerging & Conflicts

After fixing a conflict in app.js, what do you run before committing?

Predict the outputhardMerging & Conflicts

What happens after git merge --abort during a conflict?

Multiple choicemediumMerging & Conflicts

When can Git do a fast-forward merge?

8Merge Conflicts

Read the lesson
Fill in the blankseasyMerge Conflicts

Complete the command that keeps your own branch's version of a conflicted file.

git checkout -- style.css
Multiple choiceeasyMerge Conflicts

In conflict markers, what's between <<<<<<< HEAD and =======?

Multiple choicemediumMerge Conflicts

After editing a conflicted file, how do you mark it as resolved?

Multiple choicemediumMerge Conflicts

What does the zdiff3 conflict style add?

Multiple choicehardMerge Conflicts

During git rebase main, what does --theirs refer to?

9Undoing Changes

Read the lesson
Fill in the blankseasyUndoing Changes

Complete the command to unstage logo.png without losing your changes.

git   logo.png
Multiple choicemediumUndoing Changes

A bad commit has already been pushed and your teammates have pulled it. How should you undo it?

Multiple choicemediumUndoing Changes

What does git reset --soft HEAD~1 do?

Predict the outputeasyUndoing Changes

After git stash, what does git status show?

Multiple choicehardUndoing Changes

A bad commit is already pushed and shared. What's the safest way to undo it?

Fill in the blankseasyStash

Complete the command that saves your changes with a description.

git stash   "half-done header"
Multiple choiceeasyStash

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

Predict the outputmediumStash

You run git stash twice. Which stash is stash@{0}?

Multiple choicemediumStash

Which option includes untracked files in a stash?

Multiple choicehardStash

What does git stash branch fix-wip stash@{0} do?

11Remotes, fetch & pull

Read the lesson
Fill in the blankseasyRemotes, fetch & pull

Complete the command that downloads new commits without changing your files.

git 
Multiple choiceeasyRemotes, fetch & pull

What is origin/main?

Multiple choicemediumRemotes, fetch & pull

What does git pull do?

Predict the outputmediumRemotes, fetch & pull

git status says "Your branch is ahead of 'origin/main' by 3 commits." What should you do to share them?

Multiple choicehardRemotes, fetch & pull

What's safer than git push --force when you must update your own rebased branch?

12Tags & Releases

Read the lesson
Fill in the blankseasyTags & Releases

Complete the command that creates an annotated tag.

git tag  v2.0.0  "Second major release"
Multiple choiceeasyTags & Releases

What's the main difference between a tag and a branch?

Multiple choicemediumTags & Releases

Which kind of tag should you use for a release?

Predict the outputmediumTags & Releases

A project is at version 2.4.1 and you fix a bug without adding features. What's the next version?

Multiple choicehardTags & Releases

How do you share every local tag with origin?

Fill in the blankseasyRebase

Complete the commands that replay your feature branch onto main.

git switch feature
git  main
Multiple choiceeasyRebase

What happens to the hashes of rebased commits?

Multiple choicemediumRebase

After fixing a conflict during a rebase, what do you run?

Predict the outputmediumRebase

In an interactive rebase, a commit is marked fixup. What happens to it?

Multiple choicehardRebase

What does the golden rule of rebasing say?

14Cherry-Pick

Read the lesson
Fill in the blankseasyCherry-Pick

Complete the command that copies commit a1b2c3d onto the current branch.

git  a1b2c3d
Multiple choiceeasyCherry-Pick

Does cherry-pick move the original commit?

Multiple choicemediumCherry-Pick

What does the -x option add?

Predict the outputmediumCherry-Pick

Which commits does git cherry-pick A..C apply, if the history is A then B then C?

Multiple choicehardCherry-Pick

When is cherry-pick a poor choice?

15Reflog & Recovery

Read the lesson
Fill in the blankseasyReflog & Recovery

Complete the command that shows where HEAD has been.

git 
Multiple choiceeasyReflog & Recovery

What does HEAD@{2} mean?

Multiple choicemediumReflog & Recovery

Which of these can the reflog help you recover?

Predict the outputmediumReflog & Recovery

Git says Deleted branch fix (was 7c6b5a4). Which command restores it?

Multiple choicehardReflog & Recovery

What does ORIG_HEAD point to after a rebase?

16Bisect & Blame

Read the lesson
Fill in the blankseasyBisect & Blame

Complete the commands that begin a bisect with the current commit marked as broken.

git bisect 
git bisect 
Multiple choiceeasyBisect & Blame

What search method does git bisect use?

Predict the outputmediumBisect & Blame

About how many tests does bisect need to search 1,000 commits?

Multiple choicemediumBisect & Blame

In git bisect run, what exit code means "skip this commit"?

Multiple choicehardBisect & Blame

Which command finds commits that added or removed the text "sendEmail"?

17Git Hooks

Read the lesson
Fill in the blankseasyGit Hooks

Complete the command that makes a hook script executable.

 +x .git/hooks/pre-commit
Multiple choiceeasyGit Hooks

Which hook runs before a commit is created?

Multiple choicemediumGit Hooks

How does a hook stop a commit?

Multiple choicemediumGit Hooks

What does a commit-msg hook receive as $1?

Multiple choicehardGit Hooks

Why should important rules also be checked in CI, not only in hooks?

18Submodules

Read the lesson
Fill in the blankseasySubmodules

Complete the command that adds a submodule.

git  add https://github.com/acme/ui-kit.git vendor/ui-kit
Multiple choiceeasySubmodules

What does the parent repository store for a submodule?

Multiple choicemediumSubmodules

You cloned a project and the submodule folder is empty. What do you run?

Multiple choicemediumSubmodules

After git submodule update --remote, what else must you do so teammates get the new version?

Multiple choicehardSubmodules

When is a package manager usually a better choice than a submodule?

19Worktrees

Read the lesson
Fill in the blankseasyWorktrees

Complete the command that creates a worktree with a new branch based on main.

git worktree  ../shop-hotfix -b hotfix/login main
Multiple choiceeasyWorktrees

What is a Git worktree?

Multiple choicemediumWorktrees

Why does git worktree add ../x feature/search fail if feature/search is open in your main folder?

Multiple choicemediumWorktrees

You deleted a worktree folder with your file manager. What should you run?

Multiple choicehardWorktrees

Why can a worktree be better than stashing for an urgent fix?

20Team Workflows

Read the lesson
Fill in the blankseasyTeam Workflows

Complete the command that starts a branch for a fix.

git switch  fix/login-redirect
Multiple choiceeasyTeam Workflows

In the feature branch workflow, where does new work happen?

Multiple choicemediumTeam Workflows

What makes trunk-based development different?

Multiple choicemediumTeam Workflows

Which commit message follows Conventional Commits?

Multiple choicehardTeam Workflows

Which project best suits Git Flow?

21Git Partial Staging and the Index

Read the lesson

After the lab's second save, which price would an immediate commit record?

22Git HEAD, Detached HEAD and Revision Syntax

Read the lesson

In the supplied lab, what does inspected..main list after creating inspected at v1?

23Git .gitattributes and Line Ending Normalization

Read the lesson

Under the practice rules, which ending is requested for deploy.cmd at checkout?

24Git Large File Storage and Binary Asset Workflows

Read the lesson

What should git show :banner.bin display after the lab stages the matching asset?

25Sign and Verify Git Commits and Tags

Read the lesson

In the lab, which principal should %GS report after successful verification?

26Git Patches with diff, apply, format-patch and am

Read the lesson

After the first patch-lab example, what did git apply --index create in receiver?

27Git Sparse Checkout and Partial Clone

Read the lesson

Why can git ls-tree show apps/api/server.txt after the lab hides that path?

28Git Bundle Files for Offline Transfer and Recovery

Read the lesson

Why can restored import the incremental.bundle in the worked task?

29Reuse Git Conflict Resolutions with Rerere

Read the lesson

After the second merge in the lab, why does git ls-files -u still list entries?

30Git Refspecs and Explicit Force-With-Lease Checks

Read the lesson

Why does Bob's first push fail even though he uses force-with-lease?

Next steps