Starting a Repo & Identity
Creating a Repository
Turn any ordinary folder into a Git repository with one command:
$ git init
Initialized empty Git repository in /home/labuser/project/.git/
That single command creates a hidden .git/ directory inside the folder. *That folder is the repository - every commit, branch, and piece of history you'll ever create lives inside it as plain files. Everything else in the folder (your actual code) is just the working copy* Git is watching. Delete .git/ and the history is gone forever, but the folder itself just goes back to being an ordinary, untracked directory.
Tip: Runls -laright aftergit initif you're curious - you'll see the new.gitentry sitting alongside your normal files. You never need to open or edit anything inside it by hand.
Before your very first commit, Git needs to know who you are, because every commit gets permanently stamped with an author name and email:
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
| Command | Purpose |
|---|---|
git init | Start tracking the current folder |
git config --global user.name | Set your commit name |
git config --list | Show current config |
git clone <url> | Copy an existing remote repo (its files and its history) |
Tip:--globalsets your identity for every repo on your machine, written into~/.gitconfig. Drop--globaland run the same command inside a specific project to override it just for that one repo - handy for keeping a work email separate from a personal one.
Warning: A classic beginner trap: runninggit initinside a folder that's already inside another Git repo (for example, accidentally running it in your home directory, or inside a subfolder of a project you already initialized). This creates a nested, orphaned repository that behaves strangely. Ifgit statusever surprises you by not showing files you expect, check withgit rev-parse --show-toplevelto confirm which repo root you're actually in.
Try it below: git init a folder, then set a name and email, and confirm with git config --list.