Published on

How to git push in IntelliJ IDEA (or Android Studio) with a key combination


This tutorial goes through how to git push your current changes using a key combination. You won't need to write a commit message to push, so you can focus on business and shipping.

Why is this a thing?

If you working solo on projects for profit, commit messages give you 0 benefits. Instead, they only slow you down.

If you are worried that you will introduce a bug and you won't be able to figure out which commit introduced the change, have a look at git bisect. If you are worried that you will destroy your history, see git reflog.

tldr: you don't need commit messages if you are working on your own projects solo.

Overview how this works

  1. Create a script that pushes any changes to origin when it is run
  2. Create an IDEA configuration that runs push script when run
  3. Bind the configuration to a keyboard shortcut
  4. Push, ship, profit, repeat

Create the push script

Create a script that will run some git commands when executed. I use zsh to write custom scripts that I can access via any terminal instance.

For ZSH you can do this by editing the ~/.zshrc file and adding this script to the file:

function pushNow() {
    git add .
    git commit -am "PUSH"
    git push

when your run pushNow via your terminal it will create a git commit with the commit message "PUSH", it will include all changes, and push to origin.

Create an IDEA Configuration to run the push script with

Create a new Shell Script configuration, make sure to run it in terminal.

Bind the IDEA Configuration to a keybinding

Install the Run Configuration As Action plugin.

This allow will allow you to set key bindings to your run configurations. This means that you will be able to the git push action using a key combination.

Then assign a keybinding to the configuration. I use control + option + command + Enter to push straight away.

How to add git push in all your projects

I have not found a way to automatically add this to all your projects at once. When I create a new project I copy paste the xml configuration in my .idea/workspace.xml mentioned earlier and then I can push code again.

Add this code to your .idea/workspace.xml:

<!--Place this block inside the <component name="RunManager"> block -->
    <configuration name="PUSH!" type="ShConfigurationType">
      <option name="SCRIPT_TEXT" value="pushNow" />
      <option name="INDEPENDENT_SCRIPT_PATH" value="true" />
      <option name="SCRIPT_PATH" value="" />
      <option name="SCRIPT_OPTIONS" value="" />
      <option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
      <option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
      <option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
      <option name="INTERPRETER_PATH" value="/bin/zsh" />
      <option name="INTERPRETER_OPTIONS" value="" />
      <option name="EXECUTE_IN_TERMINAL" value="true" />
      <option name="EXECUTE_SCRIPT_FILE" value="false" />
      <envs />
      <method v="2" />
<!-- </component />-->

Note that the above is the configuration I noticed the IDE generates after following the steps. Depending on your script and confi names, this code might looks slightly different.

PS: This blog post was deployed after pressing cmd + option + command + Enter on my MBP. Happy shipping!