Git Init

Anonymous contributor's avatar
Anonymous contributor
Published Jul 27, 2021Updated Mar 5, 2022
Contribute to Docs

In Git, init is used to initiate the process of creating a repository. When beginning a new project, this is the first step to take in order to track changes to the code throughout all files and folders.

  • Use our beginner friendly Git course to integrate Git and GitHub and manage versions of your projects using Git branches.
    • With Certificate
    • Beginner Friendly.
      4 hours
  • Learn about the command line, starting with navigating and manipulating the file system, and ending with redirection and configuring the environment.
    • With Certificate
    • Beginner Friendly.
      4 hours

Syntax

git init

Initializing a Git Repository

Step 1: Navigate to the Desired Directory

The init command initializes a Git repository in the current directory. Prior to using this command, users must take care to navigate to the appropriate directory — this will become the root directory of the repository. The cd command can be used to navigate the filesystem from the command line:

cd go/to/desired/project/directory

Step 2: Init

In the appropriate directory, initialize a repository to begin tracking changes made to all the files with the following git command:

git init

After the initialization is complete, the following should appear in the command line.

Initialized empty Git repository in /go/to/desired/project/directory/.git/

A new, hidden .git directory is then added alongside the new repository’s root directory. In this case, the root directory is directory.

All contributors

Contribute to Docs

Learn Git on Codecademy

  • Use our beginner friendly Git course to integrate Git and GitHub and manage versions of your projects using Git branches.
    • With Certificate
    • Beginner Friendly.
      4 hours
  • Learn about the command line, starting with navigating and manipulating the file system, and ending with redirection and configuring the environment.
    • With Certificate
    • Beginner Friendly.
      4 hours