Git Init: Create Your First Local Repository
Turn a folder into a repository
git init prepares Git metadata for a repository. It does not create a GitHub repository, upload files or automatically record a commit. Use the fresh practice folder from the previous lesson. If you are unsure where you are, run pwd. The -b main option selects the initial branch name; a branch is a name used to follow a line of commits. The initial branch has no commit yet.
Inspect the new repository
A normal new repository has a hidden .git directory holding Git’s internal data, including configuration and object storage. Working files live outside that directory. Do not edit or delete .git to fix problems. Some advanced layouts use a .git file pointing to metadata elsewhere. git status is a read-only inspection of the project state for our purposes; on the fresh empty lab it reports branch main, no commits yet, and no files to commit. Exact wording depends on locale and version.
Where does the repository end?
Create a new empty subfolder called drafts inside the practice repository. Git can find the repository from its descendants; git rev-parse --show-toplevel prints the root directory of the working tree. The result ends in your practice folder’s name, not drafts. This is a useful diagnostic before making changes. Empty directories are not recorded as standalone files in normal Git snapshots.
Create a working file
In the practice root, create a new file named notes.txt with the following content using a text editor. If a file with that name already exists, do not overwrite it. Save the file, then run git status --short. In the fresh lab the result is ?? notes.txt: Git sees a file that has not been added to tracking. Saving it in your editor did not make a commit.
Verify and avoid common mistakes
Run the command below and check for the untracked file. If you see many unrelated files, stop and verify the repository root instead of staging everything. Re-running ordinary git init in an existing repository does not erase its history, but is unnecessary here. If -b is unsupported, use a supported newer client for this course; older git init without -b may choose a different name. Next, configure a local identity before recording your first commit.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Init: Create Your First Local Repository — knowledge check
Apply the lesson to common beginner scenarios.
What does git init create in a fresh ordinary folder?
What is the effect of -b main on a new repository?
What does ?? notes.txt mean in git status --short?
From the drafts subfolder, which command identifies the working tree root?
Why should you avoid deleting .git?