Setting up a Green Branch

Lately, I've been working on short chores. Most of them can be finished in an hour or less. To keep my productivity high, while waiting for the CI test for said chore, I would start another chore. At the time I finished the second chore and the first chore's tests were all green, I need to submit a merge request and wait for the approvals. That is another waiting time, which means that I can start the third chore while waiting for the second chore's tests to finish.

Working with git means that every chore will start on its own branch. Usually, my workflow when starting a new branch was like this:
  • Checked out the master branch,
  • Pulled the latest commits from remote repository,
  • Looked for the latest green tag (which is a commit in master that has passed the latest test),
  • Copy that tag name,
  • Check out the tag,
  • And finally check out a new branch from that tag.
Those are the 6 steps to do for just a chore. Imagine that for like 5 chores a day, I can have 30 steps to repeat every day. And that eventually irritated me. So, I started figuring out how to make it easier.

Checking out some bash-it git aliases, and reading some stackoverflow posts, I realized that I can remove some of those steps. I don't have to check out the master branch and pull the commits just to get the latest tags. Instead, I can do this:

git fetch --tags

Or, even shorter.

git fetch -t

Got the first and second step covered. Next, I need to get the latest tag's name. Stackoverflow says it can be done this way:

git describe --tags $(git rev-list --tags --max-count=1)

From git rev-list reference, --max-count=n equals -n, so I can have it shorter.

git describe --tags $(git rev-list --tags -1)

And, to check out that tag, just prefix the command with git checkout, of course.

git checkout $(git describe --tags $(git rev-list --tags -1))

That gives me a new bash alias.

alias gcog='git fetch -t && git checkout $(git describe --tags $(git rev-list --tags -1)) && git checkout -b'

Maybe not the nicest or coolest name, but I like that name. It is easy to remember, gcog for git checkout green (branch).


Comments

Popular posts from this blog

Using Value Object as an ActiveRecord Attribute

Kafdrop: I can see you, Protobuf

How to Upgrade PostgreSQL 10 Cluster to 12 in Ubuntu 20.04