Skip to content

Coding practice

Git Coding Questions

12 hands-on challenges with prompts and solution sketches for Git interview rounds.

Challenge set

12 coding questions

1. Stage and Commit

bash

Stage all and commit with a message.

git add .
git commit -m "Add interview questions hub"

2. Create Branch

bash

Create and switch to a feature branch.

git switch -c feature/coding-hub

3. Rebase Onto Main

bash

Rebase current branch onto main.

git fetch origin
git rebase origin/main

4. Interactive Soft Reset

bash

Undo last commit keep changes staged.

git reset --soft HEAD~1

5. Stash Work

bash

Stash including untracked files.

git stash push -u -m "wip coding pages"

6. Cherry Pick

bash

Cherry-pick a commit onto current branch.

git cherry-pick abcdef1

7. Amend Message

bash

Amend the last commit message only.

git commit --amend -m "Fix typo in commit message"

8. Show Diff

bash

Show staged and unstaged diffs.

git diff
git diff --staged

9. Recover File

bash

Restore a deleted tracked file.

git restore --source=HEAD -- path/to/file

10. Bisect Start

bash

Start a bisect session.

git bisect start
git bisect bad
git bisect good v1.0.0

11. Clean Untracked

bash

Preview then remove untracked files.

git clean -nd
git clean -fd

12. Log Graph

bash

Show a compact branch graph.

git log --oneline --graph --decorate -n 20