DEV Community

Cover image for Improving the DX with Git Aliases
Danilo Assis
Danilo Assis

Posted on

Improving the DX with Git Aliases

Photo by Roman Synkevych πŸ‡ΊπŸ‡¦ on Unsplash

Improving your DX (developer experience) is a cheaper investment in your career. You can always compose and find better improvements to existing ones.

By focusing on this, you can avoid manual work and get more time to focus on important issues.

In this tiny blog post, let's learn how to improve our developer experience by combining git aliases and the gh cli.

How to know where to improve
Start to look for repeated issues. You are tired of doing every day and every moment with that one.

And using git daily was one of those for me. So, it was time to improve it.

Fewer bits with git aliases
First, I started writing git aliases for the most common commands I was using. My routine was:

git status
git pull origin main
git checkout -b branch/name
git add file-name
git commit -m "feat(commit): message"
git push origin branch/name
Enter fullscreen mode Exit fullscreen mode
  • update main: git pull origin main
  • open a new branch: git checkout -b branch/name
  • add the files git add file-name
  • add the commit message git commit -m "feat(commit): message"
  • push the changes to the origin repo git push origin branch/name
  • go to the git hub on the pull requests page
  • open a new pull request and merge

This routine has many repeated bits for every command and in every new pull request.

So, I decided to create my git aliases:

co = checkout
st = status
cob = checkout -b
cim = commit -m
alias = ! git config --get-regexp ^alias. | sed -e s/^alias.// -e s/\ /\ =\ /
pom = pull origin master
poma = pull origin main
Enter fullscreen mode Exit fullscreen mode

Check my list and how to add it here https://gist.github.com/daniloab/04e45c7f4145ce185c7898a25e25892a

With this change, the flow of creating a new pull request started to have fewer bits but still had room for improvement.

git st
git cob branch/name
git add --a
git cim "feat(commit): message"
gh pr create --fill
Enter fullscreen mode Exit fullscreen mode

gh cli
Even with the new git aliases, the action to open new pull requests still has the pain of going to the git hub and doing everything to make it possible to open a new pull request.

A cool thing here is that git was also facing the same pain. So then, they created the gh cli, which is a cli to help with git commands.

Then, having my aliases already done, I just need to compose with the gh cli. There are many commands to open new repositories, branches, commit, pull requests, etc. The commands for status, open a branch, and add a new commit were ok with git aliases. I was looking to improve the part of creating a new pull request. And, the git cli could serve this to me with the gh pr create.

https://cli.github.com/manual/gh_pr_create with the flags you prefer.

Then, I just need to open the pr filling with the commit message. The final commands for an open a pull request are:

git st
git poma
git cob branch/name
git add --a
git cim "feat(commit): message"
gh pr create --fill
Enter fullscreen mode Exit fullscreen mode

Terminal aliases
We can accord that it has fewer bits than the starter commands. But, the gh cli for still a bigger command. Then, I add it to a terminal alias called gcpf:

alias gpcf="gh pr create --fill"

Having the final result as:

git st
git poma
git cob branch/name
git add --a
git cim "feat(commit): message"
gpcf
Enter fullscreen mode Exit fullscreen mode

gpcf + two enters to type the command and confirm the opening of a new pull request

Always improve
The final result works great for me, I can use them daily and have fewer bits than at the start. But, I can continuously improve and find better solutions.

My next step is to combine the commands of open a branch, add the git message, and open a pull request in one command only. It is not harder, and I just set a little time to do this.

If you have an idea for this, comment below. Also, share it with us if you have an awesome DX for git routine.

Follow me on Twitter
If you like and want to support my work be my patreon
See more in https://linktr.ee/daniloab.

Top comments (2)

Collapse
 
ddanielsantos profile image
Daniel Santos

Looks good, I'll give it a try

Collapse
 
daniloab profile image
Danilo Assis

Try it and tell me if will works!