Git fundamentals

Initialize a repository

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

8 minute lesson

~~~

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.

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.

Exercise: initialize an empty practice folder. Run git status, create notes.txt, then run git status again. Explain why the file is visible but not yet part of a commit.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →