Git Init Command

Git Init Command

The git init command is the first command that you will run on Git. The git init command is used to create a new blank repository. It is used to make an existing project as a Git project. Several Git commands run inside the repository, but init command can be run outside of the repository.

The git init command creates a .git subdirectory in the current working directory. This newly created subdirectory contains all of the necessary metadata. These metadata can be categorized into objects, refs, and temp files. It also initializes a HEAD pointer for the master branch of the repository.

Creating the first repository

Git version control system allows you to share projects among developers. For learning Git, it is essential to understand that how can we create a project on Git. A repository is a directory that contains all the project-related data. There can also be more than one project on a single repository.

We can create a repository for blank and existing projects. Let’s understand how to create a repository.

Create a Repository for a Blank (New) Project:

To create a blank repository, open command line on your desired directory and run the init command as follows:

$ git init  

The above command will create an empty .git repository. Suppose we want to make a git repository on our desktop. To do so, open Git Bash on the desktop and run the above command.

The above command will initialize a .git repository on the desktop. Now we can create and add files on this repository for version control.

To create a file, run the cat or touch command as follows:

$ touch <file Name>

To add files to the repository, run the git add command as follows:

$ git add <file name>  

Create a Repository and Directory Together:

The init command allows us to create a new blank repository and a directory together. The empty repository .git is created under the directory. Suppose I want to create a blank repository with a project name, then we can do so by the git init command. Consider the below command:

$ git init NewDirectory

For more Git Related post click here.

  1. Git add Command
  2. Git Commit Command
  3. Git Clone Command
  4. Git Config Command
  5. Git Alias Command
  6. Git Checkout Command
  7. Git Pull Command
  8. Git Push Command
  9. Git Fetch Command
  10. Git Status Command
  11. Git Revert Command
  12. Git Remove (rm) Command
  13. Git LOG Command