Combining git commands into one terminal line

May 2nd 2015 - Code

Having to write

git pull origin branch_name

followed by

git add all -A


git commit -m "blaaah blaah"

was getting a bit annoying so I figured out how to combine these into a single command as most of the commits I make are quite straight forward.

First thing you need to do is find your .bash_profile which should be in your home/user directory (I’m using a MAC here, no idea where it would be for other OS’s).

Second, make sure you take a copy of it in case something screws up.

Then open it up and write this function in there.

gitty() {
	git pull origin : ;
	git add . ;
	git commit -m "$1";
	git push ;

Save then file, quit and relaunch terminal. Now whenever you make a change to your git repo and want to commit something simply type

gitty "this is the commit message"

No more annoyance. What this function does is combine multiple commands at the same time. Simples.

PS – I call this gitty, but you could name it what ever you want.