Skip to content
gitbeginner

Git Basics Quiz

Commits, branches, staging area, and fundamental Git operations.

7 questions

By EZ4Code Team

1. What does `git init` do?

Creates a new local Git repository
Clones a remote repository
Initializes a commit
Installs Git
Explanation: `git init` creates a new empty Git repository in the current directory (creating a `.git` subdirectory). To copy an existing remote repo, use `git clone`. To make your first commit, use `git add` and `git commit`.

2. What is the staging area (index) in Git?

A place to prepare changes before committing them
The remote repository
A backup of your code
The commit history
Explanation: The staging area (index) is where you place changes you want to include in the next commit. Use `git add` to stage changes, `git status` to see what's staged, and `git commit` to snapshot the staged changes. This two-step process lets you craft commits carefully.

3. Which command stages a file for commit?

git add file.txt
git add .           # stage all changes
git add -p          # stage hunks interactively
git add
git stage
git commit
git push
Explanation: `git add <file>` stages changes. `git add .` stages everything in the current directory. `git add -p` lets you stage specific hunks interactively. `git commit` snapshots staged changes; it does NOT stage them.

4. What does `git commit -m "msg"` do?

Saves a snapshot of staged changes with a message
Pushes changes to the remote
Stages all changes
Creates a new branch
Explanation: `git commit -m "msg"` creates a commit with the staged changes and the given message. The `-m` flag provides the message inline; without it, Git opens your editor. Only staged changes are committed — unstaged changes are left alone.

5. Which command shows the commit history?

git log
git history
git show
git list
Explanation: `git log` shows the commit history. Useful flags: `--oneline` (compact), `-n 5` (last 5 commits), `--graph` (branch visualization), `--author=name` (filter by author). `git show` displays a single commit; `git history` and `git list` don't exist.

6. What does `git status` show?

Current branch, staged changes, unstaged changes, and untracked files
The commit history
The remote URL
The Git version
Explanation: `git status` shows the current state: which branch you're on, what's staged, what's modified but unstaged, and what's untracked. It's the first command to run when you're unsure of the repo state. Use `git status -s` for a compact view.

7. What does `git clone <url>` do?

Downloads a full copy of a remote repository to your machine
Creates a new empty repository
Merges two repositories
Pushes your changes to the remote
Explanation: `git clone <url>` copies a remote repository (including all history, branches, and tags) to your local machine. It also sets up the `origin` remote pointing to the source URL. Use `git pull` to fetch new changes later.

More git Quizzes