FresherTechnicalGit
What is the difference between git add, git commit and git push?
Try answering first
Model answer
They move your work through three places, one step each.
git addcopies the current version of files into the staging area. It decides what goes into the next commit.git commitrecords the staged snapshot in your local repository as a new commit with a message and author. It still lives only on your machine.git pushuploads your local commits to a remote such as GitHub, so teammates can fetch them and CI can run.
git add src/login.ts
git commit -m "Add login validation"
git push origin main
Because commit is local, you can commit many times offline and push later. If you edit a file after git add, the new edit is not included until you add it again.
Check where you are with git status: it shows staged, unstaged and unpushed work (use git status -sb for a short view with ahead/behind counts).
Takeaway: add chooses, commit records, push shares.
Key points
- add stages changes
- commit records a snapshot locally
- push uploads commits to a remote
- Edits after add are not in the commit until re-added
Likely follow-ups
- What does git commit -a do?
- How do you check which commits are not pushed yet?
Common mistakes
- Thinking commit already shares the work with teammates
- Forgetting to re-add a file edited after git add