Custom Git Commit Push Alias
By WretchedGhost
- 2 minutes read - 293 wordsI normally don’t create nor use tons of aliases in my .bashrc file. I have a few that tweak how grep and ls show color in the prompt and others where I can change directory by typing .. or … which perform cd ../ and cd ../../ respectively, but because of my roaming nature, where I bounce around from one computer/server to another where it may or may not have a configured .bashrc nor .vimrc, I have always tried to keep my dot-config-files mostly vanilla. My bashrc can be found here: github.com/wretchedghost/bashconfig I am also of the mind that aliases can make you dumb since you will be relying on the alias you created and not on what the alias might be doing in the background, but I digress.
After using git and entering git add . && git commit -m “changes” && git push for the thousandth time I took it upon myself to get some easier things rolling for my commits. Here is what I came up with.
$ vim ~/.bashrc
...
# Alias for Git committing and pushing
alias gitc="git add . && git commit -m" # + commit message
alias gitp="git push" # + remote and branch names if required.
...
Essentially what this does is I can type $ gitc “whatever I want” and it will run git add . && git commit -m “whatever I want”, saving me from typing much more than what needs to be typed. gitp is simple and mostly doesn’t have to exist but it helps me remember there is a gitc and a gitp command I can use to commit and push.
You can also run $ gitc “changes I made” && gitp which will add, commit, and push all in one.