GIT is a new and light weight source code control system. The best thing about GIT is that it does not have client-server concept. It can be installed and used in Windows, Linux and Mac as well. There is also a portable version available for those who want to carry the beast wherever they go.
So, here is a brief description of how to install and use GIT in your system.
Step 1: Downloading and installing GIT
- On Windows you can simple download and install the executable from here.
- On Linux/Unix you can either download and compile it from the source code or use a package manager to install it. On DEB based systems like Ubuntu and Debian use “apt-get” and in RPM based systems like Fedora and CentOS use “yum”.
Debian: $sudo apt-get install git-core gitweb
RPM: #yum install git
For other systems instructions are available here
Step 2: Setting up repository
Lets consider that there are 2 PCs. One of them is the remote PC which we use as the main repository for holding the source and another one is one from where we add to the source or checkout from the origin.
So, in remote PC after installation of GIT you need to choose a place where you would like to store all your project files. Let us consider you place all your files in home directory of a user. For easy and manageable way create a user named “git” and assign it a password. For this do the following in Linux system.
$useradd -m git -s /bim/bash
$passwd git
Now create a directory under the home directory “/home/git/”. Note that you need to logout and login as “git” user. Do the following then.
$mkdir git_repo //creating a directory for storing the project files, now it will be our GIT repository
$cd git_repo //change the directory to the newly created directory
$mkdir first_project //create a new project directory
$cd first_project //change to the project directory
$git init //initialize an empty repository
Now, in the local machine where you want to checkout the repository, create directories to store the project files.
If you are on Windows, run the git-bash shortcut on your desktop. Linux users can use any terminal of their choice. I prefer GUAKE or YaKuAKE.
$mkdir local_git_repo
$cd local_git_repo
$git clone git@SERVER_NAME_OR_IP:/path/to/git_repo/first_project
This will clone the remote repository to local machine. You will be asked for the password of user “git”. Enter the password and you are done. You will get a repository at current working directory.
Step 3: Adding files and commit them in repository
Now, you already have a directory of current project inside your local GIT repository. Now, we will try and add some files in the repository. For this purpose do as follows.
$cd first_project //enter into the new project directory
$vim index.php //create a new file index.php, write something in it and save and quit using “:wq”
$ls //lists the files in the direcoty
$git status //shows the status of current repository
$git commit -a -m “Index File Added” //commit the changes in the repository
$git add index.php //to add index.php to the repository listing, if you want to add many files at once, you can do “git add -a” instead
At this point or before this it is better to setup the global username and email. So do this:
$git –global user.name “Your Name”
$git –global user.email “Your Email”
Now, you can push the changes in the original remote repository as follows.
$git push git@SERVER_NAME_OR_IP:/path/to/git_repo/first_project master //this will push all the commit to the master branch of the repository
Now, you have a repository called first_project in the server SERVER_NAME. To verify whether changes have been comitted in the server you can delete the existing local repository and run a “git clone” again, this will create the repository in the local machine with updated files.
Well, that what I did to setup and use a GIT repository as version control system. I hope that will help you as well. For advanced and detailed instructions you can view the documentation of official GIT site here.


















