Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Push Code Like A Boss With "git gg"

5/30/2018

0 Comments

 
Regardless of what language you're coding in, you need to use some type of version control for any serious project. Personally, I like using the command line to push my code to a git repository (and if you're going to try to argue that your git GUI client is better- please, the command line is faster to use, lighter on your machine, and just gives you the most control). Although I love using git from the shell, I found myself repeatedly doing the same three commands over and over:
  • git add -A
  • git commit -m "commit message"
  • git push
Originally, I was just looking for a way to at least combine the add and commit steps into just one command. I learned that you could add a "-a" flag onto the end of commit, but that's not quite the same as add -A. I even started this reddit thread about the subject, and it was from these answers that "git gg" was born.

Git gg - It's Just A Git Alias

It was the great suggestion of alfunx to use a git alias in the first place. We can create a global git alias with a single command that will be available in all command shells on your machine from the time you run it onward forever and ever, and you can name it whatever you want! I personally like "gg" because it's very short and just gives me a nice feeling reminiscent of defeating and then trolling a tough opponent in an online multiplayer game. In this case you have defeated not another person, but git itself. You have tamed the wild, ferocious, time-sucking beast and boiled it down to a mere 2 letters.   
Anyway, here's the command to add the git alias: 
git config --global alias.gg '!f() { git add -A && git commit -m "$@" && git push; }; f'
In this above command we define and then return a shell function, f, where we then run the three commands: git add -A, git commit -m, and git push. Notice that we can even take the string passed into git gg and use that as our commit message in the git commit command by referencing it with "$@". Pretty dang nifty. Also, shoutout to my friend Christina for giving me the idea to add the git push right there in the function to be run when the commit finishes.

Removing A Git Alias

If for some unthinkable reason you might want to delete this magically fantastic git alias, you can easily do that with the --unset flag:
git config --global --unset alias.gg

Just Do It

It's literally just one command to set up this git alias, and trust me it will make your life so much better (assuming you push or want to push to git frequently). This command works on Mac, Linux, and Windows so you have no excuse! Create it, use it, live it. Don't forget to high five me in your mind every time you use this and laugh at how ingeniously efficient you are.

Taking It One Step Further 

For different programming languages you will have different build systems, cli tools to run tests, etc., but I highly doubt you could find one that doesn't have some concept of pre-commit git hooks. For Nodejs front-end or backend projects I like to use a library called husky. With this package installed all you need to do is define a script called pre-commit in your package.json file, and have it run any commands you'd like to have passing before the code can be committed. I like to load up this command with an eslint command, unit tests, smoke tests, integration tests... It's just very awesome to only have to type "git gg" and a short message and then watch as your command prompt get flooded with stuff happening all while you, the puppet master, can happily sip your tea or coffee or beer or water. Code on, my friend, and keep pushing code like boss.
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021