switch·Esc back

Git

You might say

AI broke my code. I want to get back to the last version that worked.

Keep a history of code changes so work can be compared and restoredGit records snapshots of a project and lets people compare changes, create independent branches, and combine work. Each developer has a full local history. GitHub and similar services host repositories and collaboration, but they are not Git itself.
Know first
Files changedThese edits are not committed yet
Create a commitcommit
Homepage update committedThe snapshot is now in local history
Upload commitspush
GitHubThe remote repository now has the commit
Git tracks commits; GitHub hosts the remote repository

Commit a coherent set of changes to local history, then push those commits when you want to share or back them up on GitHub. Uncommitted edits are not included in a push.

When to use it

  • Save meaningful code changes
  • Compare the current work with an earlier state
  • Develop separate ideas on branches
  • Collaborate through a shared remote repository

When NOT to use it

  • Commit passwords, tokens, or environment secrets
  • Treat Git as a backup for generated files and large binaries
  • Combine unrelated changes in one unclear commit
  • Run unfamiliar destructive commands without checking the target
Anatomy
💻 Working tree Files you are editing git add → 📥 Staging areaChanges selected for the next commit git commit → 🗄 Local repository Your commit history git push → ☁️ Remote repository GitHub
Files changed in your working tree that are not yet committed
git add stages selected changes for the next commit; it does not move the file itself.
git commit records the staged changes as a new commit in local history.
git push publishes local commits to a remote repository so collaborators can fetch them.
Typical use cases
Feature development
Commits · main
ML
Fix mobile navigation alignment
10 minutes ago
c7d8e9f
ML
Build homepage layout
2 hours ago
a1b2c3d
ML
Initialize project
3 days ago
0f1e2d3
Bug fix
zsh — my-first-page
$ git log --oneline c7d8e9f Fix mobile navigation alignment a1b2c3d Build homepage layout 0f1e2d3 Initialize project Each line shows a commit ID followed by its message
Team collaboration
zsh — my-first-page
$ git revert c7d8e9f [main f4e5d6c] Revert "Fix mobile navigation alignment" Creates a new commit that reverses the selected commit without deleting history
Release history
my-first-page
📄 index.htmlBuild homepage layout2 hours ago
📄 README.mdInitialize project3 days ago
📄 .gitignoreInitialize project3 days ago
Further reading