If you want to understand how changes travel from your messy laptop to sacred commit history you need three players in the drama. The working tree is your filesystem where you edit files. The index is the staging area that holds the snapshot you plan to commit. The repository stores committed snapshots and the HEAD pointer tells you which one is current. We will use tiny examples and actual git
commands so you can stop guessing and start winning.
Run git init
then git status
to prove the repo starts empty and lonely. Create a file named hello.txt
and add some text. Run git status
again and you will see the working tree has an untracked file. That means the file exists on disk but Git has not been told to care about it yet.
git init
to create a repogit status
to inspect the working treegit add hello.txt
to stage a fileUse git add hello.txt
then try git status --short
or git ls-files --stage
to inspect the index. Think of the index as a photo studio where files get their glamour shots before going public. The index records a snapshot that will become the next commit.
Edit hello.txt
again and use git diff
to compare the working tree with the index. To see what you have staged versus the last commit use git diff --staged
. These two diffs are your best friends when you want to avoid accidentally shipping half baked work.
When the index looks right run git commit -m 'add hello'
. Then run git log --oneline
to view the repository history. The repository now stores the committed snapshot and HEAD moves with each commit. That is the life cycle from working tree to index to repository.
git add
git commit
Tip Use git status --porcelain
for machine friendly output and git restore --staged
to unstage files if you change your mind. No drama required. Now go break something and then fix it like a champ.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.