How can I make this git command alias?

I want to make an alias as shown below

gc this is a test message converted to git commit -m "this is a test message" .

How can i do this? I want this in my bashrc.

+4
source share
4 answers

This is not an alias, but try

 function gc() { git commit -m "$*" } 
+6
source

bash alias definitions do not accept parameters.

Try using the bash function in your .bashrc:

 function gc () { git commit -m "$*" } 
+9
source

I have this alias in my .bashrc:

 alias ga='git add' alias gp='git push' alias gl='git log' alias gs='git status' alias gd='git diff' alias gdc='git diff --cached' alias gm='git commit -m' alias gma='git commit -am' alias gb='git branch' alias gc='git checkout' alias gra='git remote add' alias grr='git remote rm' alias gpu='git pull' alias gcl='git clone' 

I usually commit with gm "msg"

+6
source

This should work:

 alias ci = "!f() { git commit -m \"$*\"; }; f" 

Unfortunately, gc is already a subcommand and cannot be an alias.

+1
source

Source: https://habr.com/ru/post/1379599/


All Articles