1

Alright, googling this for 10 minutes and the only examples I find are about aliasing things like commit -m, but how would I alias a command such as git commit -m? I tried using git config --global alias.gco "git commit -m" but this too only worked with the first command (commit -m). I also tried manually adding that command to the gitconfig file, but that didn't work either.

Is this impossible?

What i want to achieve:

I want to alias this: git commit -m So that instead of typing in git commit -m, I just type in gco

15
  • Have you tried git config --global alias.gco 'commit -m' ? I'm pretty sure I don't understand your question. Commented Jun 13, 2017 at 12:33
  • Try this github.com/GitAlias/gitalias/blob/master/gitalias.txt#L234 Commented Jun 13, 2017 at 12:34
  • @LasseV.Karlsen yes, aliasing that command works, but aliasing the git commit -m command does not work. Sorry, there was a grammar mistake, must be where your confusion rooted from. Commented Jun 13, 2017 at 12:35
  • But then if the first works, why do you even need to try something else? Doesn't the one that works do what you want? Commented Jun 13, 2017 at 12:35
  • 2
    Git alias can only be used to add or modify(?) commands invoked through git, you can't create new top-level commands that isn't invoked using git, in other words if your entire command line is supposed to be gco message, and not git gco message, then you need to create a shell script or batch file or similar named gco that invokes git. Git alias alone can't solve this. Commented Jun 13, 2017 at 12:44

1 Answer 1

10

As per information you provided in the comments, it looks like you want bash alias, rather than git.

Following will allow you to make a commit via gco from the command line:

# Add me to your ~/.bashrc
alias gco='git commit -m'

But this is git alias, executed via git gco:

git config --global alias.gco "commit -m"
Sign up to request clarification or add additional context in comments.

1 Comment

Please note, I wrote this answer as readable as possible. If you are nerd, please replace bash with shell, .bashrc with whatever is suitable for your shell, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.