GIT · FOUNDATIONS
Git basics: working tree, staging, commits and branches
Git is a version-control system that records file history. Saving an edit, selecting content, committing it and transferring history are distinct actions. Follow a small SQL change to see exactly which content becomes part of a commit.
Distinguish the saved file from the next commit, then explain branches and remotes.
Start with files and folders. No GitHub account, AWS account or database connection is required. States shown here are teaching assumptions.
Separate editing, selecting, recording and sharing
Editable files on your machine. Saving does not create a commit.
Select content for the next commit; git add updates this selection.
Record selected content in history, separately from later edits.
Transfer history to another repository, which need not be on GitHub.
These stages select, record and optionally share content. A remote is optional; review and deployment are separate.
A repository manages the history of a project. Git works with a local repository alone. GitHub can host shared history and collaboration, but is not required to use Git. Begin by identifying the content on your own machine.
The index does not follow later edits automatically
In the fictional sql/monthly_report.sql file, add region = JP to the approved-report filter and suppose this content is staged with git add. Then edit and save an additional month filter. The working tree can now contain JP plus month, while the index still contains JP alone.
| Stage | Working tree | Index | Latest commit |
|---|---|---|---|
| Before editing | Approved filter | Approved filter | B: approved filter |
| After staging JP | Approved + JP | Approved + JP | B: unchanged |
| After editing month | Approved + JP + month | Approved + JP | B: unchanged |
| After a normal commit | Approved + JP + month | Approved + JP | H: approved + JP |
A normal git commit records the index. The unstaged month edit is excluded from H in this example. Saving a change and including it in a commit are different events. Inspect the differences before deciding whether to stage again or leave unfinished edits out.
Choose the diff for the comparison you need
| Command | What it shows |
|---|---|
| git status | Working-tree and index change states |
| git diff | Working tree versus index |
| git diff --staged | Index versus current commit |
| git log | Commit history |
| git branch | Local branches |
| git remote -v | Configured remote names and destinations |
A diff describes differences between two states. Reading it does not apply or approve the change. Use the working-tree comparison for the unstaged month edit and the staged comparison to see what would enter the next commit. Always identify both sides.
A commit need not move another branch
A commit records content and history relationships; a branch names a commit. Creating H on feature/jp-report-filter can leave main pointing at B. Integrating into another branch is a separate operation. B and H are teaching labels, not real hashes.
Check the content and destination before sharing
A remote gives a name to another Git repository location. The common name origin does not imply GitHub. A push updates allowed remote references; it does not send arbitrary uncommitted working-tree files.
- Verify the destination repository and intended sharing scope.
- Keep credentials and customer data out of history. A deletion commit does not remove earlier copies.
- Verify transfer separately from PR review, merge, build and deployment.
Check the state distinctions
Choose an option to see the result and explanation.
Check, then explain in your own words
- Explain the saved and staged versions.
- Explain why main and feature can point at different commits.
- Check the destination and sensitive content before sharing.
Check your understanding: Does a month filter edited after staging automatically enter normal commit H?
No. H records the staged JP filter in this example.
The commit reads the index, separately from later working-tree edits.
Sources and conditions checked
Primary references are collected here with their scope, conditions and corresponding sections. Independent expert review and live-environment validation have not been performed.
Scope and conditionsWorking tree, index and commits; edits made after staging. Documentation review, not live-environment validation.
Used in this lessonSeparate editing, selecting, recording and sharing The index does not follow later edits automatically Choose the diff for the comparison you need Check the state distinctions
- Git: Working with RemotesChecked:
Scope and conditionsRemotes and pushing; destination and update rights are separate conditions. Documentation review, not live-environment validation.
Used in this lessonSeparate editing, selecting, recording and sharing Choose the diff for the comparison you need Check the content and destination before sharing Check the state distinctions
- Git: Branches in a NutshellChecked:
Scope and conditionsBranches as movable references to commits. Documentation review, not live-environment validation.
Used in this lessonChoose the diff for the comparison you need A commit need not move another branch Check the state distinctions