Initializing a new repository

If you want to create a repository in an existing project, just type the following command line:

Erik@local:~$ cd myProject
Erik@local:~/myProject$ git init .

Otherwise, you have to create an empty directory and type git init inside it, as shown:

Erik@local:~$ mkdir myProject
Erik@local:~$ cd myProject
Erik@local:~/myProject$ git init

This will create a folder named .git inside the current directory that contains the following files used by Git:

  • Config: This is used with the configuration for the local Git repository
  • HEAD: This lists a file that is the current head branch
  • Refs directory: This contains references to a commit for a branch

Get Git Best Practices Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.