git init
The "init" command creates a brand new Git repository.
Running the command in a directory on your computer will create a new .git
subdirectory there. This is the actual, local Git repository and it contains all structure and metadata that make up a Git repository.
Note that just running git init
in an existing project will not add any existing files to the new repository. git init
only creates a blank repository; it is your duty to then deliberately add commits to it.
Usage Examples
Although there are a couple of options for git init
, you will almost always use it with no other arguments:
$ git init
This command will create a new and empty Git repository in the current working directory. It doesn't matter if other files in this directory existed or not; the command only creates the .git
repository folder.
If you would then like to put your current project files under version control, you can make your first commit:
# Add all files to the staging area (= tell Git to include them in the next commit)
$ git add .
# Wrap these changes in a commit and save them to the local Git repository
$ git commit -m "First commit"
In case you are using the Tower Git client, you can simply drag and drop your project folder - and then create your first commit with a couple of simple clicks:
Learn More
- Find the full command description in the Git documentation
- More frequently asked questions about Git & version control