When working in a team of developers we usually use Pull Requests (PR) to show what we are working on and ask for feedback and code review.
Our team uses a special feature flag called TEMP, that can be used to embrace any code that is unfinished without breaking our product for our customers.
TEMP flag lets us work in small pull requests, focusing on a single issue, merging then in master before they are completed finished. We have issues or task that would take more than a week to complete and code reviewing all this code would be hard and error prone.
Given this scenario we create many pull requests throughout the day. Let's see how a “naive” workflow of a pull request looks like:
git checkout -b <branch> (create a new change for the pull request)
git add <files> (add changed files to git)
git commit -m ‘<message>’ (commit changes)
git push origin <branch> (push changes to remote, usually github)
open browser
navigate to repository
go to pull request tab
open pull request, fill pull request title and body
We would need to do this 8 steps many times over the day, this can be error prone, also waste our time and be boring. Let's see if we can automate some of this steps.
Hub
The slowest part was the browser navigation and clicks, so I decided to use Hub to create pull request directly from command line, this is the new workflow:
git checkout -b <branch> (create a new change for the pull request)
git add <files> (add changed files to git)
git commit -m ‘<message>’ (commit changes)
git push origin <branch> (push changes to remote, usually github)
hub pull-request -m (open pull request)
We cutted from 8 steps to 5 steps, all of them running in the terminal. The problem is that hub won't fill the title and body of the pull request. Let's see if we can fix and reduce even more this steps.
GitHub CLI
GitHub decided to build their own cli.
I was skeptical at first to migrate from hub and my almost good PR workflow. However they launched a new argument to their pull request command that fill the title and body using commit information, see the final workflow:
git checkout -b <branch> (create a new change for the pull request)
git add <files> (add changed files to git)
git commit -m ‘<message>’ (commit changes)
gh pr create --fill
We also reduced it to only 4 commands. gh pr also auto pushes the changes to the proper branch, so you don't need to worry about it, it can also handle many commits and it will add each commit message in the body of the pull request.
Can we improve more?
I bet we can.
If you use Information Theory, you can use less bits to represent the most common commands to make them fast. In practice you use git alias or bash alias, to type less to achieve the same thing.
You can also use ctrl+r to search bash history to typing even less
Thanks for the reading, let me know what topics should I cover next