Setting up a local git repository

Photo by RetroSupply on Unsplash

Setting up a local git repository

Git is one of the most popular version controlling system out there. It is a free and open source version controlling system. Git has become an integral part of software development. Git is a distributed version controlling system meaning multiple developers can work on their own feature or even better, multiple developers can work on a single feature.

Most of us when working with git tend to associate git with Github, Bitbucket and other services. When in reality, git, due to its distributive nature, can be used to version control anything locally and does not require any online services to function. You can use git once you have installed the Git on your computer. Online services such as Github are merely providing platform for collaborating on a project.

In this article, we will be diving into git concepts and commands which will increase your confidence in git.

Initiating a local git repository

We need to initate a directory as a git repository. Once it is completed, we will be ready to perform version controlling inside the directory. First, we will create a folder named learning-git and initialize it as a local git repository.

$ mkdir learning-git

After the directory is created, we will change the directory to learning-git and run git init command which will initiate our repository.

$ cd learning-git
$ git init
Initialized empty Git repository in /home/pidalu/learning-git/.git/

We will also run ls -A command to view all the directories in the directory including the hidden ones.

$ ls -A
.git

We can see that a .git directory was created inside the directory. Git uses this directory to store and track changes. Getting rid of this directory means that git will not be able to track changes in the directory.

We have now successfully created our local git repository. We can create any files or directories inside this directory and git will be able to track those changes. In our next blog, we will dive into how we can track those changes.