Essential Git Commands and Their Boundaries
Fast recall
Quick revision
Core answer
git status compares the working tree and staging area with the current commit; git add copies selected changes into the staging area; git commit records the staged snapshot in the local repository; git pull fetches remote commits and integrates them into the current branch; and git push sends reachable local commits to a remote branch. add does not upload code, commit does not include unstaged changes, and push does not first bring remote work into your branch.Whether you know the core loop (status, add, commit, push, pull) and the model (working dir -> staging -> commit -> remote).
Committing without checking git status (staging the wrong files), or not branching for features.
Core loop: status, add, commit, push, pull. Model: working dir -> staging (add) -> commit -> remote (push). Branch per feature; merge to combine.
Interview-ready guide
Interview answer
Git tracks snapshots through a local workflow before anything reaches a server. The working tree contains the files I am editing, the staging area—also called the index—contains the proposed next snapshot, and the current commit is the last recorded snapshot on the branch.
git status explains the differences between those states. git add app.rb stages the current content of that file. If I edit it again, the new edit remains unstaged until I add it too. git commit then creates a local commit from exactly what is staged, together with its parent and message.
For example, after fixing a validation I run git diff, stage the implementation and its test, inspect git diff --staged, and commit them together. Unrelated debugging output remains in the working tree instead of leaking into the commit.
git pull is a convenience operation that first fetches remote references and then integrates the selected upstream branch, normally by merge or rebase according to configuration. git push sends local commits and asks the remote reference to advance. A push can be rejected if the remote branch has work I do not yet contain.
The key boundaries are that add is not an upload, commit is not a server action, and unstaged edits are not part of a normal commit. I use status and staged diff before every commit so the recorded snapshot says one clear thing.
Essential Git Commands and Their Boundaries
Direct Answer
git status compares the working tree and staging area with the current commit; git add copies selected changes into the staging area; git commit records the staged snapshot in the local repository; git pull fetches remote commits and integrates them into the current branch; and git push sends reachable local commits to a remote branch. add does not upload code, commit does not include unstaged changes, and push does not first bring remote work into your branch.
Deep Dive & Architecture
A new edit begins only in the working tree. Git can show how it differs from the index with git diff. Staging copies the chosen version into the index; it does not freeze the file, so later working-tree edits can exist beside a staged version of the same path.
A commit turns the index into an immutable repository object and moves the current branch reference to it. Other local branches and remote-tracking references do not move automatically. This is why a developer can create several commits while offline and publish them later.
Fetching and integrating are separate ideas. git fetch updates knowledge of remote references without changing the working tree. A merge combines histories with a merge commit when necessary; a rebase replays local commits onto a new base. pull performs a fetch followed by the configured integration strategy, so checking the branch and working state first prevents surprises.
Pushing asks a remote to update one or more references. Normal servers reject a non-fast-forward update because it could discard commits that already exist there. Incorporating remote work and resolving conflicts locally creates a history the remote can accept without losing another person's snapshot.
Code Example
git status
git diff
git add app/models/order.rb test/models/order_test.rb
git diff --staged
git commit -m 'Validate positive order quantity'
git pull --rebase origin main
git push origin feature/order-validation
Common Mistakes & Pitfalls
Committing without checking git status (staging the wrong files), or not branching for features.
Check your understanding
Answer these without looking back at the article.
- Can one file have both staged and unstaged changes?
- What two operations are normally performed by `git pull`?
- Why can a remote reject a normal `git push`?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.