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
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.