You can enforce git messages by using custom git shortcuts in shell/bash script.
So, we use JIRA and bitbucket, and the good thing with them is that they integrate very well with each other, e.g.
- it links JIRA issues in your Bitbucket PRs
- you can change Jira status from within Bitbucket
- you can create development branches from inside JIRA issue
But this needs some effort to ensure the consistency in your git messages and branch names, plus if you can follow a certain pattern, it becomes for everyone to collaborate since everyone is following the same set of rules.
So here are a couple of rules that we follow for branch management and commit messages:
- git branch name
- commit message
JIRA-1234 some actually useful commit message
- set a ticket
In Progressonce you start working on it
These are pretty straight forward, and I believe some of you are also following these rules (or at least some variation of it). But sometimes you forget to actually follow these, and this gets caught in PR reviews, or sometimes get merged.
3. Use git aliases
2. Use bash aliases (Easiest)
1. Use own implementation of bash functions (Most powerful & coolest)
Git aliases are cool, and you can create your own shortcuts for common tasks
git co instead of
And here is how you can do it yourself.
$ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.ci commit $ git config --global alias.st status
You can use config files to manage aliases e.g.
[alias] co = checkout
You can read more about it here
Bash aliases are another approach similar to creating your own shortcuts (that are even shorter than the above approach).
vimor any other text editor
- Add this to bottom of your file
alias gco="checkout" alias gbr="branch" alias gci="commit" alias gst="status"
- Save it
source ~/.bashrcOR restart terminal
gco masterand you will see that you are now on master and our command is working.
You can have a look at common aliases here
This is the most tricky, but most powerful approach. With this, you can do cool things like:
- auto add JIRA id to commit message
- get JIRA status in your bash terminal
- Directly open PR URL of your current branch in your browser
- and many more
The way I do is, define some env variables like your username, jirapassword, etc, and do a curl request to get status.
You can also append the JIRA ticket number automatically to commit messages using bash functions.
Here is the gist for the same:
- Download this file
- Source it in
ghto get a list of available commands
gcof JIRA-1234 # create a branch with username piyush-JIRA-1234 gpoh # push changes at HEAD right now gopr # Open the new PR link for your current branch jira # show Jira status of the current branch
Do the same here as you did above for