DEV Community

Ali GreenHeart
Ali GreenHeart

Posted on

git advanced aliases

Alt Text

Hi! Today, I wanna show you how to configure your git add commit push alias. Scenario is like this, I was thinking is there any way to shorten famous add commit push brothers. In one article, it was written that it's impossible. But, actually, it is possible. And we just need to add alias to our (in fact it's not ours, but lemme call it our) .gitconfig file .
At first, let's look are there any alias? in our .gitconfig:

git config --global -l

command shows all alias from your .gitconfig. Probably, your user name and email had been written to there. And if you had added any alias(es), then those aliases were there too. If you don't, then there will not be even an alias word in there :)

Let's add some aliases. There are 2 ways to do it:

  1. Go root file and edit .gitconfig file 2. git config --global alias.aliasName "yourCommand"

For example, git config --global alias.addAll "git add .". After executing this command your new alias will be added to your .gitconfig file. (at following picture you see all my aliases)
Alt Text

Btw, as you see, I added -c http.sslVerify=false because, I can't push my codes to my repo at work, that's why I did it. You can just, write git push too.

We have created our simple alias which is the alias of one command. But, if we want to create alias for multiple commands we can't in this way. So, that's why article said it's impossible write multiple commands in this why, but it is possible to do it with other way. Let's call that way "function_style" way.
Step 1. Open your .gitconfig file
Step 2. Add this line after alias. How I did in and you see that at previous picture.

addcompush = "!f() { git add . ; git commit -m \"$1\" ; git  push ; }; f"
Enter fullscreen mode Exit fullscreen mode

I called it addcompush, a bit crazy name, but still sounds great // or comes to me great :) !

Calling this alias is like this:

git addcompush "your commit message"

Have fun 🌹💚!

Top comments (2)

vishalraj82 profile image
Vishal Raj

@ali_gh I use more of such combination such as

  • checkout a branch and take a pull at the same time - git cop - Checkout & pull
  • ammend to previous commit with no edit of message - git cane - Commit, amend and no edit
  • After fixing conflicts - git amc - Add and continue with merge
alion_greenheart profile image
Ali GreenHeart

yeah, definitely you can, I use such things with gui ))