Git tricks to be more productive

Julio Santana
3 min readJan 28, 2021

I like to use git command line. It is simple, it comes out of the box with many Linux distributions, it is IDE independent so you might be hacking in any language you like, you simply need to come there and push your changes. However, some day I found myself spending too much productive time in typing git commands, linking them to Jira tasks to make them more traceable and the usual thing that we developers need to do to get our work done and I decided to spend some time trying to improve that.

Here is what I did.

1. Shortcuts

Bash shortcuts for git is something I heard a long time ago and never tried. Now I can only recommend them. To get them ready I used this very practical post

Bash shortcuts are like small new commands that you declare to refer to more verbose ones. This can be done in the file that is executed at startup in your distribution ~/.bash_profile or ~/.bashrc so they are available in the next restart and always from command line.

There can be also functions which allow you to execute more logic than a simple command. I end up with this list in my file

# ----------------------
# Git Aliases
# ----------------------
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gcm='git commit --message'
alias gco='git checkout'
alias gp='git pull'
alias gs='git status'
alias gst='git stash'
alias gstp='git stash pop'
# ----------------------
# Git Functions
# ----------------------
# Git log find by commit message
function glf() { git log --all --grep="$1"; }
# Create a new branch in local and in remote
function remoteb() {
git checkout -b "$1";
git push origin "$1";
}

2. Use jira command line

Another time consuming and distracting task was to go to Jira to get the number and name of the task I am working on every time I needed to do a commit. I use to do this to keep track of the task this commit is solving, and to benefit from the great capability all Atlasssian products have to be linked between them. The commit text might be stored in bash history and that’s fine but most of the time it is not and in your travel to the browser you can loose the focus of your current task.

To fix this the command line tool go-jira came very handy. It just ask you to define the basic config of your Jira server (url and user) in $home/.jira.d/config.yml a config file and then you just need to provide the password from the command line to get it going

endpoint: https://jira.yourcompany.com/
user: jsantana
login: jsantana
authentication-method: session

After this you have a very long list of options to query task, dashboards and everything inside Jira, but to be honest I mostly use it with custom commands, which you can define in the config file and later call them as if they were a new options

custom-commands:
- name: my-tasks
help: display issues assigned to me
script: |-{{jira}} list — template table — query “assignee = currentUser() AND resolution = Unresolved”

and you end up with Issue id, summary, etc, ready to be piped into your next git command.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Julio Santana
Julio Santana

Written by Julio Santana

Software Engineer. Blockchain Enthusiast

No responses yet

Write a response