Repositories
By the end of this lesson
Create or clone a repository and understand what is tracked.
A repository is an ordinary folder with one extra thing inside it: a hidden directory called .git that holds the entire history of the project.
Nothing else about the folder changes. Your files stay where they were, your editor opens them the same way, and the programs that read them do not know or care. Git adds a record alongside your work rather than taking your work somewhere else.
Three names for parts of that folder, used constantly from here on:
- Working directory
- The files you can see and edit. This is the version of the project that exists right now, including changes you have not recorded yet.
- The .git directory
- The history: every commit, every branch pointer, and Git's own bookkeeping. It sits in the top folder of the repository. Delete it and you have a plain folder again with no history at all.
- Tracked and untracked files
- A tracked file is one Git already knows about, because it appeared in a commit or you have staged it. An untracked file is sitting in the folder with Git deliberately ignoring it until you say otherwise.
There are two ways a repository comes into existence, and they suit different starting points:
| git init | git clone | |
|---|---|---|
| Starting point | A folder on your machine, with or without files in it | A repository that already exists somewhere else |
| What you end up with | A repository with no commits yet | A repository with the full history already in it |
| Is a remote configured? | No — you add one later if you want to share the work | Yes, named origin, pointing at where you cloned from |
| Typical use | Starting a new project of your own | Joining a project, or picking up work from a shared repository |
# Start a repository in a folder you already have
cd invoice-service
git init
# Or take a copy of one that exists, history included
git clone https://github.com/example-org/invoice-service.git
# Either way, this is the command you will run most often
git status- git init creates the .git directory. It does not add any of your files to the history — it only makes the folder capable of holding one.
- git clone creates a new folder named after the repository, downloads the whole history into it, and checks out the default branch so you have working files to look at.
- git status is your position report: which branch you are on, what has changed, and what is staged for the next commit. Run it when you are unsure, which at the start will be often.
Immediately after git init, git status will list your files as untracked. That surprises people who expect Git to have picked everything up. It is deliberate. Git waits to be told what belongs in the history, because plenty of what sits in a project folder should never be recorded: compiled output, downloaded dependencies, editor settings, local configuration files holding passwords.
You decide what is worth keeping. The cost of that decision is one extra step. The benefit is that a repository contains the project rather than the debris around it.
Summary
- A repository is a normal folder plus a .git directory holding the full history
- git init starts a repository with no commits; git clone copies an existing one with its history and a configured remote
- Git tracks nothing until you tell it to, which keeps build output and local configuration out of the project
- Every clone is a complete copy, so reading history, branching and committing all work offline
Practice
Attempt each one before opening the solution. Getting it wrong first is how the idea sticks.
Try it yourself
Try it yourself
Create a folder called expense-tracker, put a single text file in it, and run git init followed by git status.
Read the output carefully. Which branch are you on? What does Git say about your file, and what does it suggest you do next?
Show solution
You will be on the default branch, usually named main, with no commits yet. Your file is listed as untracked, and Git suggests git add to begin tracking it.
The important observation is that the file is present but unrecorded. The folder and the history are separate things, and at this moment the history is empty.
mkdir expense-tracker
cd expense-tracker
git init
git statusThink about it
Think about it
You clone a repository, then lose your internet connection. Which of these can you still do: read the full commit history, create a branch, make a commit, see a colleague's new work?
Show solution
The first three work offline. Your clone contains the whole history, so reading it, branching from it and adding to it are all local operations.
Seeing a colleague's new work is the exception, because their commits are not in your copy yet. That requires contacting the remote, which is what fetch and pull do — covered later in this course.
This is worth internalising early: almost everything in Git is local. Only a handful of commands talk to the network.
Saved in this browser only.