I am really happy that I can use git for my every day job. Earlier I was only using it in hobby projects. Now I can learn and experience git in real projects, with real people and problems. So far, I love it :)

There is one nice ‘feature’ of git that i found recently : creating git custom commands. It is useful, when I want to automate some repetetive tasks.

Repetitive Task

git add -A
git commit -m '@Projectname'

Whenever I want to commit changes to the branch, I have to execute add command and then perform a commit. ‘Projectname’ is one of the conventions in my company. Each commit needs this variable beacuse we are using it in internal mail service.

One of my practices with source control systems, is to commit a lot, so doing this ‘repetition’ all the time is a waste of time.

Git Custom Command - git c

Custom command specification :

  • execute git add
  • execute git commit
  • commit message with project name

All this is simple except the project name variable. Fortunately our projects folders are named after the project. In the Script, I just have to get its name.

Script

#!/bin/sh
#
# git-c
#
# Michal Franc
# quick add + commit

git add -A
git commit --message="@${PWD##*/} $1"

Installation process

  1. go to libexec/git-core folder (@Windows 'C:\Program Files (x86)\Git\libexec\git-core')
  2. create new file in this folder called 'git-c' (no extension)
  3. copy paste the script code

Usage

git c 'test commit'