A website starts with a few files. Git gives you a way to record what those files looked like at particular points in time. The project files and the history together make up your local Git workspace.
Git · Lesson 1
Repositories
Learn what a Git repository stores and start an empty repository for a small website.
Creating a Repository
Start in a practice directory where you can create a new folder. Run the following commands once. The dollar sign shows the shell prompt.
$ mkdir journey-git
$ cd journey-git
$ git init --initial-branch=main
The new folder is your working tree, where you edit project files. Git creates a hidden .git directory there to store history and settings. This new repository has no saved changes yet. Git calls the initial line of work main.
You initialize a repository that already contains index.html. What happens to that file's history?

Recognizing the Working Tree
Use git rev-parse --show-toplevel to print the root of the current repository. A shell inside the practice folder should report a path ending in journey-git. A folder inside that working tree still belongs to the same repository unless it contains a separate repository of its own.
$ git rev-parse --show-toplevel
You enter a subdirectory named images in journey-git. Which directory should Git report as the top level?
Starting with Existing History
Use git clone when there is already a repository you want to copy. A normal clone creates a new local working tree and imports the existing repository history. Use git init for a project whose history you are starting locally. You will keep using journey-git in the following lessons.
A teammate gave you the address of a repository whose history you need. Which starting action fits?
Lesson complete
You finished Repositories
You can now choose how to start a local Git repository.
Identify the working tree and Git's hidden directory.
Find the root when you are in a subdirectory.
Choose initialization for a new history or cloning for an existing history.
Keep your learning progress
Create a free account to save this lesson and continue learning on any device.
Create a free account