how to configure a git repository

Sarath Pillai's picture
git repository

Hi all, Before biginning with this post i will recommend reading the below posts as a prerequisite.

Introduction to git version control system

how to install and configure git

Now in this post we will be covering the most important and the most used parts of git version control system.We will be going through the following things in this post.

  • Configure and initialize a git repository
  • cloning a remote repository
  • staging and commiting changes

The first requirement, to work with a git repository is to ofcourse get/ or make a git repository. This can be done in multiple ways.

1.You can make a project, your git repository

2.or you can download/fetch an aready made repository from a server and start working in your own copy of repository.

Initializing a git repository

For initializing a git repository, we need to first go to the directory where the project is. Suppose a group of developers are working on a project, and the project's source code is all kept in the directory /home/john/myproject. Now inroder to create the directory myproject(containing the source code of the project) a repository we will do the following things.

$ git init

this command will create a directory(.git) similar to our normal .ssh folder in the home directory. This .git folder will contain all the required files for a repository. Yet we have not started to track anything in our project.

In order to start tracking our repository we need to tell git what all files in the directory needs to be tracked, which can be done by the following command.

$git add *.sh (will add all files ending with .sh to the git repository)

$git add text(will add the file named text to the git repository)

the above two commands adds the files to the git repository. git add command means that we are telling git to start tracking the files.

Now after adding those files, we need to commit our changes, by the following command.

$git commit -m "bigining version of myproject"  (as told in the previous posts, commit will be a snapshot for a particular state of the project. the -m used in the command is just a commit message for humans to understand about the commit, and this can be anything)

in the above case this will be our first state of the project.

One important thing to understand in git is that, each and every file in a repository can be either tracked or untracked.

Tracked files are those files which were present in your last commit(they can be modified or unmodified).

We will be coming back to these concepts after learning how to clone a git repository.

Cloning a git repository

during the above discussion of initializing a repository, we only discussed how to create a repository out of a project in your home directory. Now lets understand how to clone an already made repository from a remote machine(cloning can be understood as making local copy of a remote repository, so that you can work in that repository)

Cloning a git repository will pull down all the things related to that repository, such as the history of the projects,all versions of the project,commit logs etc.In other words it will be a complete mirror of the original repository.

cloning a git repository can be done by the following command.

$git clone <URL ADDRESS>

if suppose the localtion of the git repository is /myproject on the server then we can clone this by the following command.

$git clone git://

the above command will create a directory named myproject, at the location where you ran the command. that myproject directory will be your local repository, and will have the .git directory inside it.

Now if you want to clone the remote repository into some other directory name, other than the default one then you can do that by the following method.

$git clone git:// <directory name>

git uses a number of different protocols for its operation, in the above case we used the git protocol. you can even use http,and even ssh.


Whenever you edit files, in your repository(no matter whether its cloned or initialized by urself),git recognizes it as modified since the last commit. The changes are staged, and the contents of the staged things are commited and made a snapshot.

We can easily check the status of the files in our local repository by the following command.

$ git status
If you get an output with the string "nothing to commit(working directory clean)" then that means that your repository does not have any changes to commit.

the status command aslo tells us something about the branch you are in(will explain about branches in git in upcoming another post).

Thank You all...

Rate this article: 
Average: 4 (2 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.