Full lesson
Explore the full explanation, examples, and visuals at your own pace.
An edit is not a commit
An edit to app.js isn’t automatically part of your next commit. Git separates the editable working tree from the index, where you select the content for a future snapshot. The diagram’s git add connection marks that boundary: until you add the file, its edit isn’t staged.
git add records selected content
Git add app.js takes its current contents from the working tree, updates app.js’s entry in the index, and stores that content as a blob in Git’s local object database. This is still local; it hasn’t been published to the remote.
What the index selects
The index holds the selected version for each path: app.js as staged, along with any other files already staged. If you edit app.js again afterward, that newer working-tree content isn’t included until you stage it too.
- A version of app.js
- Other files' previously staged versions
- Not later unstaged edits
git commit snapshots the index
Git commits the staged snapshot, not every edit in the working tree. The index builds a tree, and the commit refers to that tree, keeping unstaged changes out. Branch names point to commits, not directly to files.
main points to the new commit
The index builds a tree, and the commit references that tree. After git commit, local main moves to point at the new commit. A branch name is a movable reference; moving it doesn’t replace the commit or its snapshot, which remain stored as Git objects.
Commits link backward
The Index builds a Tree snapshot, and the Commit references that snapshot while recording its Parent. The new commit doesn’t replace the earlier one; it links back to it. Moving main changes which commit marks the local branch tip, while the earlier snapshot remains part of history.
You stage app.js, edit it again, then commit without staging again. Which version enters the commit?
Let's think this through. You stage app.js, edit it again, then commit without staging again. Which version enters the commit? A: The version recorded by the earlier add. B: The latest working-tree version. C: Both versions as separate commits. Choose an answer, or just think it through. I'll explain in a moment.
- The version recorded by the earlier add
- The latest working-tree version
- Both versions as separate commits
You stage app.js, edit it again, then commit without staging again. Which version enters the commit?
The answer is A: The version recorded by the earlier add. The commit snapshots the index, which still holds the version selected by the earlier add. The later edit remains in the working tree unless you add the file again.
- The version recorded by the earlier add
- The latest working-tree version
- Both versions as separate commits
Committed locally is not published remotely
Local main now points to app.js’s commit. Remote main stays at its earlier commit until a successful push updates it.
git push publishes commits
When you run git push, Local Git checks the current tip of remote main. Remote Git reports it, so Local Git can send the missing objects, including the commit containing app.js. It then requests that remote main move to the new commit. Remote checks the update and confirms or rejects it.
Same commit, two repositories
Once the push is accepted, local main and remote main point to the same commit, with the app.js snapshot. They’re still separate repositories: publishing updates the remote branch, not a collaborator’s working tree.
Stage, snapshot, publish
The working tree is editable, the index selects the next snapshot, and branch names point to commits. Git add puts selected content in the index; git commit moves local main to a new snapshot; git push updates remote main when accepted.






