user392412
user392412

Reputation: 743

How can I make this git command alias?

I want to make a alias, like this below

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

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

Upvotes: 8

Views: 4452

Answers (5)

tashicorp
tashicorp

Reputation: 499

For anyone getting error: pathspec <commit message> did not match any file(s) known to git, try this in your shell file:

alias gcam='git commit -am'

You should be able to use it like this with no problems:

gcam "potential fix - dup pageviews"

Upvotes: 0

shams
shams

Reputation: 3508

This should work:

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

Unfortunately gc is already a subcommand and can't be aliased.

Upvotes: 1

fuzzyalej
fuzzyalej

Reputation: 5973

I have these 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 normally commit with gm "msg"

Upvotes: 13

krousey
krousey

Reputation: 1798

This isn't an alias, but try

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

Upvotes: 9

John Weldon
John Weldon

Reputation: 40739

bash alias definitions don't take parameters.

Try using a bash function in your .bashrc:

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

Upvotes: 11

Related Questions