basic guide for beginners

git - the basic guide for beginners

Recently while developing a custom Drupal module for a client, I was asked to do git commit everyday. While doing it few days regularly missed one step and deleted the file difference by mistake. This made me to write down steps to follow every time for this project.

Getting started with Git

Git is a free and open source distributed version control system designed to handle small to very large projects with speed and efficiency. Git is all about composing and saving snapshot of your project.

The three main sections of Git project are index which acts as a staging area for your snapshot, Git directory where Git permanently stores the snapshot of your project  and a working directory where you can modify your files.

First step with git is cloning a remote repository

Clone to create local repository

git clone

Using clone command, you can create a working copy of a local repository. it helps you to clone a repository into a new directory.

git clone

Updating local Git repository

To fetch from and integrate with another repository or a local branch , use

git pull

It will pull down from remote whatever you ask and merge it instantly into a branch you are in when you make a request.

To extract data from remote serve to origin, use

git pull [options] [ [...]] git pull origin

Adding files

In Git, you have to add file contents to your Index before you commit them. If the file is new, you can run

git add

Using this command, files in the current state will be sent to the index for commit.

If you want to add multiple files to the index, you will have to add them as shown below

git add file1 file2 file3 ….. git add -A e.g. git add readme.txt or git add -A

This adds the files file1, file2, file3, and adds readme.txt to their updated content to the index.

Verify Status

While coding, you may want to see what all files have changed, before you do a commit to store them in the git repository. For that you can use

git status

The status command will show all files that have changed since your last commit.

Finding difference between commits

Apart from just viewing what all files that have changed, if you want to see the actual difference in the source code. use

git diff

The above command will show a difference with respect to your last commit and current changes. The git diff command can be used to compare difference between any commits.

Below command shows unified diff format as to what code you have changed in the project.

git diff [options] [] [--] [...] git diff


Git commit is used to store the changes you've made to git repository.

git commit

It stores the current contents of the index in a new commit along with a log message.


here m switch is used to specify commit message. You can put anything between the quotes for your message.

git commit -m "Adding Readme.txt"

Pushing your code back to the repository

In order to send changes made by you from your local working copy to remote repository for your branch,

You can use the command

git push -u origin git push -u origin 7.x-1.x git push -u origin master

This example shows how to push modified changes to the repository with branch master or 7.x-1.x