You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
A repository is the heart of Git — it is the folder where Git tracks all your files and stores the entire history of your project. In this lesson you will learn how to create a repository from scratch and understand what Git creates behind the scenes.
Navigate to a folder you want to track and run:
mkdir my-project
cd my-project
git init
Git responds with something like:
Initialized empty Git repository in /Users/you/my-project/.git/
The git init command creates a hidden .git folder inside your project. This folder contains everything Git needs: the object database, configuration, branch pointers, and more. You should never manually edit files inside .git.
If you want to start from an existing project hosted on GitHub or another remote, use git clone:
git clone https://github.com/user/repo.git
This downloads the entire repository — including all history — into a new folder named after the repo.
The most frequently used Git command is git status. It shows you the current state of your working directory:
git status
On a brand-new repository it reports that there is nothing to commit yet.
Not every file in your project should be tracked. Compiled binaries, editor settings, dependency folders, and secrets should be excluded. Create a file named .gitignore in the root of your project and list patterns for files Git should ignore:
# Ignore node_modules
node_modules/
# Ignore build output
dist/
build/
# Ignore environment files
.env
.env.local
# Ignore macOS metadata
.DS_Store
Git will never track files that match these patterns. If a file was already tracked before you added it to .gitignore, you need to untrack it with git rm --cached filename first.
Git uses three conceptual areas:
Changes flow from the working directory, through the staging area, into the repository. This staged approach lets you build a clean, logical commit even if your working directory has messy, unrelated edits in progress.
echo "# My Project" > README.md
git status
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.