Git and GitHub · Part 1 · Git basics
Your first repository
What a repository is
A repository (or repo) is a project folder that Git tracks: the same folder, with the save system turned on. The files don't change. Git only adds one hidden folder, .git, that holds every save point.
Creating a repository
1.Make a practice folder
cd ~/Desktop
mkdir git-practice
cd git-practiceThis makes a folder on the Desktop and moves into it. For now, it's a normal folder, and Git says so:
git statusfatal: not a git repository (or any of the parent directories): .git2.Turn Git on
git initInitialized empty Git repository in /Users/you/Desktop/git-practice/.git/The folder is now a repository. ls still shows nothing, because names starting with a dot are hidden. ls -la shows hidden files too:
ls -ladrwxr-xr-x .
drwxr-xr-x ..
drwxr-xr-x .gitIn Finder, Cmd + Shift + . shows hidden files.
3.Ask Git what's going on
git statusOn branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)The project is on the main branch (the setting from Lesson 2), with no commits and no files yet.
What's inside .git
ls .gitconfig description HEAD hooks info objects refsThis folder is the repository. The parts that matter:
| Item | What it holds |
|---|---|
objects/ | Every snapshot: file contents and commits |
refs/ | Pointers to commits, such as branches and tags |
HEAD | Where the project is right now |
config | Settings for this repository only |
hooks/ | Scripts that can run automatically, such as before a commit |
They're plain files. HEAD, for example, is one line of text:
cat .git/HEADref: refs/heads/mainThat means “on the main branch.” Git manages all of this, so there's no need to edit anything in .git. And since the whole history is in this one folder, copying the project folder to another computer copies its history too.
Adding a first file
echo "Hello Git" > notes.txt
git statusUntracked files:
(use "git add <file>..." to include in what will be committed)
notes.txtUntracked means Git can see the file but isn't tracking it yet. The hint says how to start: git add.
See these steps in a real terminal

Mistakes to avoid
- Deleting
.git. The files stay, but the whole history is gone for good. - Running
git initin the home folder or on the Desktop. Git then tracks everything inside it. Alwayscdinto the project folder first. To undo it, delete the.gitfolder that was created by mistake, for examplerm -rf ~/.git, and nowhere else. - A repository inside a repository.
git init my-new-projectcreates a new folder with its own.git. Run insidegit-practice, it makes a nested repository, which causes confusing problems. Delete it withrm -rf my-new-project, and only rungit initoutside other repositories.