The git init
command is used to create a new, empty Git repository. This is the first step in tracking your project’s changes with Git.
Initial Example
To initialize a new Git repository in your current directory, simply type:
git init
INIT Options
Option | Description |
---|---|
-q, --quiet | Suppress all output except for error and warning messages. |
--bare | Create a bare repository with no working directory. Useful for a central repository. |
--object-format=<format> | Specify the object format (hash algorithm) for the repository, such as sha1 or sha256 . |
--ref-format=<format> | Set the ref storage format for the repository. Valid options are files (default) and reftable (experimental). |
--template=<template-directory> | Use the specified directory as a template for the repository. |
--separate-git-dir=<git-dir> | Create a text file pointing to the actual repository location, useful for managing repository location separately. |
-b <branch-name>, --initial-branch | Set the initial branch name for the newly created repository. If not specified, the default branch name is used. |
--shared[=(false|true|umask|group|all|world|everybody|<perm>)] | Configure the repository to be shared among users with specified permissions, such as group , all , or custom permissions in octal format (e.g., 0640 ). |
Examples
1. Basic Usage
When you run the command in your project directory, Git will create a new subdirectory named .git
that contains all the necessary repository files. This is the basic structure of a Git repository.
git init
2. Initializing a Bare Repository
A bare repository is used as a central repository, typically on a server, that developers can push to and pull from. It does not have a working directory.
git init --bare
3. Creating a Repository in a Specific Directory
If you want to create a repository in a specific directory, provide the directory name as an argument.
git init /path/to/your/project