Git & GitHub · 10 min · 110 XP
Your first repository
Turn a folder into a repository, make your first commit, and keep secrets out of it.
git init turns the current folder into a repository. It creates a hidden .git folder, and that folder is the repository: every commit and every branch lives inside it. Your files stay exactly where they were. (Delete .git and the history goes with it.)
mkdir shop && cd shop git init # Initialized empty Git repository in .../shop/.git/ echo "<h1>Shop</h1>" > index.html git status # index.html is "untracked" git add index.html # stage it git commit -m "Add home page" # record the snapshot
Git never tracks a new file on its own. A new file is untracked until you git add it, and a commit only records what's been added (staged). That's deliberate: nothing lands in history unless you chose to put it there.
Some files should never be committed: passwords and API keys (often in .env), downloaded dependencies (node_modules/), and build output. List them in a file called .gitignore and git will act as if they don't exist. Do it before your first git add .. Once a file has been committed, it stays in history even after you delete it.
.env node_modules/ dist/ .DS_Store
$ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.env
index.html
nothing added to commit but untracked files present (use "git add" to track)Try it on your machine: make a folder, git init, add a .gitignore containing .env, create an .env and an index.html, then run git status. Only .gitignore and index.html should appear. Add them, commit, and run git log to see your first commit.
Loading your workspace…