How to install and configure Git to manage source code
Git is an open source, distributed version control system with the emphasis on being fast. It was developed by Linus Torvalds for managing Linux Kernel. It was primarily focused for Linux, but now its available for almost every operating system. Its fast on POSIX-based systems such as Linux. Its different from SVN because it creates a private repository on remote server as well. Some projects using Git - Linux kernel, YUI, Fedora, Debian, X.org, VLC, Perl, there is some work going on to shift Drupal on Git too.
Installing GIT on Fedora and Ubuntu
Lets start by installing Git and Gitweb, a web interface for Git.
[root]# yum install git-core gitweb #For Fedora/RedHat based Distros
[chia]$ sudo apt-get install git-core gitweb #For Debian or Ubuntu based distros
First thing you want to do is set up you username and email address. GIT uses colour to notify user about the crucial things so we need to activate colors as well. The following commands will do that for you.
[chia]$ git config --global user.name "Tushar Mahajan"
[chia]$ git config --global user.email "email@example.com"
[chia]$ git config --global color.status auto
[chia]$ git config --global color.branch auto
Using --global will apply it at global level. It will store the information at .gitconfig in your home directory.
[chia]$ cat ~/.gitconfig
You can check the values by using:
[chia]$ git config user.name
Now we are all set up, we need to create a Git repository.
[chia]$ mkdir project
[chia]$ cd project
[chia]$ git init
Initialized empty Git repository in /path/to/project/.git/
Now you can see there is a .git directory inside the project.
Add some description to the project:
[chia]$ echo "Short Project Description " > .git/description
Git stores its actual compressed objects in .git/object directory.
It will be empty at this point of time.
[chia]$ git add . # git add is used to add file contents to the index.
# To check what is there in the index files run
[chia]$ git ls-files
[chia]$ git ls-files --stage # this will display all the sha checksums of the indexed files.
[chia]$ git status
[chia]$ git commit
"git status" will show a list of all the new and updated files that are there in the directory.
Add all the files to the repository by using "git commit". Now running "git status" will show
# On branch master
nothing to commit(working directory clean)
To show the latest commit messages:
[chia]$ git log
Cloning GIT directory
You can clone git directory using either git protocol or using http. Git works on port 9418.
# Clone using git protocol
[chia]$ git clone git://github.com/drupal/drupal.git
# Clone using http protocol
[chia]$ git clone http://github.com/drupal/drupal.git
# Git protocol is more efficient for cloning. But in the end you will get same thing.
Now, we have successfully installed and configured Git on our system.