INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

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.

What you will learn

Distinguish the saved file from the next commit, then explain branches and remotes.

Prerequisite

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

From editable files to an optional remote
EDIT
Working tree

Editable files on your machine. Saving does not create a commit.

SELECT
Staging area / index

Select content for the next commit; git add updates this selection.

RECORD
Local commit

Record selected content in history, separately from later edits.

SHARE
Optional remote

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.

Stipulated content at each stage
StageWorking treeIndexLatest commit
Before editingApproved filterApproved filterB: approved filter
After staging JPApproved + JPApproved + JPB: unchanged
After editing monthApproved + JP + monthApproved + JPB: unchanged
After a normal commitApproved + JP + monthApproved + JPH: 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

Inspection commands and what they compare; not executed here
CommandWhat it shows
git statusWorking-tree and index change states
git diffWorking tree versus index
git diff --stagedIndex versus current commit
git logCommit history
git branchLocal branches
git remote -vConfigured 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.

  1. Verify the destination repository and intended sharing scope.
  2. Keep credentials and customer data out of history. A deletion commit does not remove earlier copies.
  3. Verify transfer separately from PR review, merge, build and deployment.

Check the state distinctions

Choose an option to see the result and explanation.

You stage a file, then edit it again. What does a normal commit record?
Read the answer and reason

Answer: The content selected in the index. · Later working-tree edits do not automatically update the index.

Which pair distinguishes unstaged edits from staged changes?
Read the answer and reason

Answer: git diff and git diff --staged. · They compare the working tree with the index, then the index with the current commit.

You create commit H on feature. What follows about main?
Read the answer and reason

Answer: main can still point to the earlier commit B. · Branches identify positions in history; integration is a separate operation.

What still needs separate evidence after a successful push?
Read the answer and reason

Answer: That the change was reviewed and is used in the intended environment. · Transferring history does not establish review, build or deployment.

Check, then explain in your own words

  1. Explain the saved and staged versions.
  2. Explain why main and feature can point at different commits.
  3. 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.