top of page

Git, lets get it…!!!

Forget the past, it cannot be changed, forgotten, edited or erased, it can only be accepted. But in a software lifecycle, forgetting history may destroy the future 😛 So, keeping track of the history is a necessity. Git is a software version control system, which helps to keep track of the code history(log), step back in the history(revert), create a new life(branch) if you are not satisfied with one 😛

In this post, I have described a few most commonly used git commands.

So guys, let’s get into git…!!!

Git setup

1. Ensure the list of available packages is up to date before installing anything new

               $ apt-get update

2. Install git

  $ apt-get install git

Creating working copy (local repository) 

1. Create a copy of existing repository

               $ git clone <path-of-remote-repo>

Saving changes

1. After changes are done in the local repository, to view the changes

      $ git diff  
               $ git status

2. To save changes to git staging area.

     $ git add <filename>

<filename> can be copied from the output of git status. It tells Git that you want to include these changes in the next commit. This will not affect the local repository (working copy)

3. Save above changes to the local repository. Only after git commit, the changes will be saved to the local repository.

 $ git commit -m "Enter commit message"

4. To add signoff to the changes done

 $ git commit --signoff

Configure git

1. All the configurations are maintained in the .gitconfig file. To view the contents of this file

              $ cat .gitconfig

2. Each commit is associated with user’s name and email address. Both can be set by

 $ git config --global "Your Lovely Name"
 $ git config --global ""

3. To view all of the above configurations set

 $ git config --list

No software is error free. Errors are the weak points of the software and these weak points are mended using patches. The affected software must be neatly patched. Also, many of the open source communities require the patches to be sent to their mailings list via email.

So let’s setup email first, before creating patches.

Setup Gmail

1. Git must be setup to send mail using Gmail account. Following are the commands to do that :

           $ git config --global sendemail.smtpencryption tls
           $ git config --global sendemail.smtpserver            $ git config --global sendemail.smtpuser           $ git config --global sendemail.smtpserverport 587           $ git config --global sendemail.smtppass <password:gmail app specific password>

Gmail requires email to be sent via TLS. We are using Gmail, so stmp server is Smtp port number is added. The user is your email address. Now the smtppass must be application-specific password. To get this password, go to your Gmail account’s ‘Security’ tab and generate the application-specific password. Copy-paste that password in the above command.

Once, the email setup is done,  let’s patch it up with git…!!!

Create neat patches

To create an appropriate patch, ready to be sent via mail.

 $ git format-patch --to <> HEAD^ --subject-prefix="PATCH v2"

This will create a file named something like 0001-name-of-my-patch.patch in local repo’s base directory. Subject (name) of the patch is the first line of the commit message used to save the changes. Usually patch subject includes something like [Patch v2], this string is included in subject-prefix. Note that square brackets are automatically added. Email recipient’s address must be included in –to option. Head^ represents the last commit.

This command will only create a patch and not send the patch to the recipient.

Send neat patches

Once the patch is created, to send it

 $ git send-email <0001-name-of-my-patch.patch>

To send the last commit

 $ git send-email -1

Above two commands will send the formatted neat patches to the recipient mentioned in the git format-patch command.

The Past may hurt, you can either run from it or learn from it. Above git commands definitely help to deal with the past so that we can learn from it and patch the hurting past 😛

Happy patching with Git 🙂 😛

Recent Posts

See All


bottom of page