Reducing redundancies while using git

With people who use git on a daily basis and use a pattern in their branch names and commit messages, for eg. for a task number, say 12345, the branch name should be ticket-12345 and the commit should be something like: refs #123456 descriptive commit message, it can become really tedious after a while. So, I wrote a bash function that you can use as an alias by adding it to the .bashrc or .bash_aliases.

	# colors
	NC='\033[0m' # No Color

        # getting the name of the branch and getting the ticket number
	branchname=$(git symbolic-ref --short -q HEAD)
	IFS='-' read -r -a array <<< $branchname


        # if we can get the ticket number, we proceed with committing
        # and pushing to origin.
        # Otherwise, we stop this procedure and show an error message
	if [ -z "$ticketnumber" ]
	    printf "${RED}Invalid branch name${NC}\n"
	    exit 1
            echo "Ticket number: $ticketnumber"
	    printf "${GREEN}Valid branch name${NC}\n"

	    git add -A
	    git commit -m "refs #$ticketnumber [email protected]"
	    git push origin HEAD

Hence, we save more power, and get work done more quickly.

Man Parvesh Singh Randhawa
Man Parvesh Singh Randhawa
Software Engineer

My interests include distributed computing, information security and Software Engineering.