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 repository
- You can clone 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 directory appears in the folder. That directory *is* the repository — all history and configuration live there. Delete it and the history is gone; keep it and every other file can be restored at any time.
Working with GIT means always knowing which of three areas a file sits in. The working directory is the actual file you see in your editor. The staging area (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. It's a strength GIT has that many other version control tools don't.
Commands for this step
Don't just read them — type them into a real terminal. Your hands have to remember, not your eyes.
git init- Turn the current folder into a new repository; `.git` appears.
git clone <URL>- Clone a remote repository in full — history included.
git status- Show the current state of all three areas. When stuck, always run this first.
ls -a- List hidden files too — see for yourself that `.git` is really there.