Search anything:

Git: Initialize a Git repository

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

Reading time: 15 minutes

In order to take the advantages of Git and begin your journey in the massive collaborative nature of OpenGenus, you need to add Git to your OpenGenus project. This is done by initializing a new Git repository.

OpenGenus loves Git

A Git repository, which is often abbreviated as just repo, is a virtual storage of your project. In other words, each project in Git is referenced as a repository.

To initialize a new project or a project that already exists, you first need to move to the project folder using the command line. This can be done using the cd command. cd stands for change directory. Assuming that our project diractory is "opengenus_project", we move to the concerned project.

Initialize git repository cd change directory command

Now that we are in the concerned folder, initializing a Git repository is done by typing the git init command. Once executed, you will then see a response message that says Initialized git repository in the specific file path of our project.

Initialize git repository git init command

By initializing your project, it added the Git configuration to a .git subdirectory that has marked this project folder and all of its contents to be version controlled. This .git subdirectory is hidden by default, but you can go into that folder by typing cd .git, and then you can use the ls command to provide a list of the files in this folder.

Initialize git repository cd .git and ls command

You will notice that there are several files that were just created and we will explore the contents and its corresponding significance at a later article. For now, you may just consider that the .git directory just contains all of the important Git metadata for this new repository.

Now, as you learn more about Git, you'll understand more about what these files do, but for now, just know that they exist. We can get out of the .git subdirectory and go back up a level to our parent directory by typing cd dot, dot. If we now type ls again, we get a list of all of the files that are saved under the project folder. Even though we have initialized Git on this project, the contents in these files have not changed, they have only been added to be version controlled by Git.

OpenGenus Tech Review Team

OpenGenus Tech Review Team

The official account of OpenGenus's Technical Review Team. This team review all technical articles and incorporates peer feedback. The team consist of experts in the leading domains of Computing.

Read More

Improved & Reviewed by:

Git: Initialize a Git repository
Share this