Git fundamentals

Initialize a repository

Turn an existing project folder into a Git repository with git init.

Move into an existing project folder, then run:

git init

Git creates a hidden .git directory. This turns the current folder into a repository, but it does not commit any files.

Check the state:

git status

Git will show the current branch and any untracked files. Your working files have not moved. Git is now ready to track selected versions of them.

On a fresh init you usually see On branch main and a list of untracked files. Nothing is broken. Git is waiting for you to stage and commit.

What lives in .git

The .git directory holds the object database, references, configuration, and staging information. Deleting it removes the repository metadata and local history while leaving the working files behind.

Do not edit files inside .git by hand.

Running git init again in the same folder is normally safe. Git reinitializes the repository instead of erasing its history. Still, always check pwd and git status first. Initializing the parent folder by mistake can make Git see far more files than you intended.

If you run git init inside ~/projects instead of ~/projects/notes-project, Git will try to track every project in that folder.

The default branch name is often main on new repositories. Older tutorials use master. The commands in this course assume main, but the ideas are the same regardless of the name.

Try this on a disposable practice folder: initialize it, run git status, create notes.txt, then run git status again. The file is visible but not yet part of a commit because Git has not recorded a snapshot of it.

Lesson completed