When I use git, most of the time I just want my local changes pushed to the remote right away so the two stay in sync. The commands I use most are:

1
2
3
git add .
git commit -m "some comments"
git push

These three commands make up about 90% of my daily use, so I wondered whether I could combine them into one to cut down on typing. My first instinct was to chain them with the shell's && operator and run them as one command.

1
git add . && git commit -m "some comments" && git push

That works, but it doesn't reduce typing. It just puts the three commands on one line, which isn't what I wanted. What about an alias? You can set the three common commands as one alias in .bashrc or .bash_profile (on Mac), like this

1
2
3
alias lazygit = “git add .; git commit -a -m ’some comments’; git push;”;
Run
$ lazygit

That's nice: type the alias and all three commands run automatically, which cuts down on typing and mostly does what we want. But on reflection, it's still not perfect. The problem is that the comment is hard-coded, so you can't write a different message for each change. It isn't flexible enough. What if we passed the comment in as an argument? Then we could write a different commit message each time. We can do that with a function in the bash config file.

1
2
3
4
5
6
7
function lazygit(){
git add .
git commit -a -m $1
git push
}
$ lazygit "my comments"

This saves typing and lets me write a different commit message each time. It seems to solve my problem perfectly. But it also goes against the workflow git was originally designed for. Then again, it's hard to make everything perfect. This is just a quick note to satisfy a lazy person's needs; no need to overthink it.