Git yolo

Olivier Picault
2 min readMar 11, 2018

As a developer I’m always trying to automate repetitive tasks. Unfortunately this isn’t always possible. Take git for example, I’m most of the time doing the same things:

  • Add files
  • Commit or amend an existing commit
  • Push all of it to the remote branch
  • Wait for CI to pass
  • Wait for fellow colleagues to review and comment my PR/MR if needed

and thus I’m always typing the same git commands.

At the beginning of my career I discovered git aliases. This was a revolution to me. Instead of typing long commands and trying to remember the right options to do what I intent to (i.e. search on Google), I only had to use two-letters words for basics commands and could create my own ones. I this started to add aliases to my ~/.gitconfig file:

# basic aliases
st = status
ci = commit
co = checkout
# aliases I made
fall = fetch --all --prune
pom = push origin HEAD -f
prom = pull --rebase origin master

This was great and I believed I had it solved.

But then few years ago, thanks to a chat with a colleague in my previous company, I discovered few things:

  • Lots of people where using reb instead of the prom I created
  • We could amend a commit and by-passing the edit commit message screen (thus saving me typing : + q to exit vim)
  • I wasn’t push forcing the right way.

Here is how my aliases looked like then:

st = status
ci = commit
co = checkout
commend = commit --amend --no-edit
fall = fetch --all --prune
reb = pull --rebase origin master
please = push --force-with-lease -u origin HEAD
  • commend: amend a commit and skip the edit message screen
  • please: push force (which is needed when you amend a commit) + track the remote branch. The difference here is that it will only push to the remote branch if no one has updated it since your last push, thus preventing deleting any work

Again that was great but this time I needed more!

Aliases are great but I would still need to type 3 commands to do what I do so frequently:

git add .
git commend
git please

I was sure I could concat the three of them in a single one. I discovered function and git yolo was born:

yolo = "!func(){ git commit --amend --no-edit -a && git push --force-with-lease -u origin HEAD; }; func"

It does everything in a single command and as you are only using it you don’t even have to type it: upwards arrow + ENTER is enough

Now here is what I type when I start a new feature:

git add .
git ci -m 'commit message'
git please

and here what I type when I need to update the branch

git yolo

--

--