The repository and its three areas
Create or clone a repository, and learn to tell apart the working directory, the staging area, and the repository. Miss this distinction and every later command will confuse you.
What you'll learn
- You can turn an empty folder into a
- You can someone else's repository to your machine
- You can draw how a file moves between the three areas
There are two ways to get a repository: git init turns your folder into one, and git clone copies an existing one wholesale. Either way a hidden .git appears in the folder. That directory is the repository — all and configuration live there. Delete it and the history is gone; keep it and every committed file can be restored at any time (uncommitted changes cannot).
Working with means always knowing which of three areas a file sits in. The is the actual file you see in your editor. The (index) is a waiting room for "things going into the next commit". The repository is where a commit has been made permanent. Files move from working directory to staging with add, and from staging to the repository with commit.
The middle step exists so you can curate commits. Even if you touched five files, you can pick the two that belong together and commit just those. That ability is what later makes history readable and lets you find the commit that broke things quickly.
Understand it easily
Imagine packing for a trip. The work folder is your room with clothes everywhere, the staging area is the open suitcase where you put only what you chose, and the repository is the sealed box with a label. git add puts things in the suitcase, and git commit seals the box.
Commands for this step
Don't just read them — type them into a real . Your hands have to remember, not your eyes.
git init- Turn the current folder into a new repository;
.gitappears. git clone <URL>- Clone a in full — history included.
git status- Show the current state of all three areas. When stuck, always run this first.
ls -a- List too — see for yourself that
.gitis really there.
Common mistake and how to fix it
Running git init in the wrong folder, such as your home folder, so every file under it ends up in the repository. Check where you are with pwd (it shows the folder you are in) first. If it already happened, run rm -rf .git in that folder to delete only the .git folder made there. Your own files stay as they are.
You mark this yourself. Nothing is graded here.
Mark this step as understood?
This cannot be undone yet, so mark it only when you really understand.
Marked as understood
You mark this yourself. Nothing is graded here.