2

Having to type git commit -m "Message" all the time has become tiresome, so I started looking up how to create shortcut commands for git.
I found out you can create git aliases with git config --global alias.cm 'commit -m', but I'd still have to do git cm "Message". I want to go even shorter.
After more looking I found out you can create windows shortcuts with the doskey command, but from what I can tell it just creates a shortcut command for an application in the PATH.

How can I create a Windows command so that I can type gcm "Message" and have it behave as if I typed git commit -m "Message"?

Edit:
My question is similar to Aliases in windows command prompt, however, it is different in that I want parameters to be supplied with the shortcut command automatically. The solution in that post requires you to enter all parameters manually, which I'm trying to avoid.

Joseph Webber
  • 2,010
  • 1
  • 19
  • 38
  • What operating system are you on? And what IDE are you using? – user1767754 Nov 23 '17 at 19:11
  • @user1767754 Windows 7. – Joseph Webber Nov 23 '17 at 19:14
  • 1
    Possible duplicate of [Aliases in windows command prompt](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt) – lucidbrot Nov 23 '17 at 19:25
  • @lucidbrot That's the post I looked at where I learned about the `doskey` command, but as I stated in my question it looks like it's just a way to create a shortcut for a command in the PATH. From what I see, you'd need to supply parameters to the shortcut every time you use it. – Joseph Webber Nov 23 '17 at 19:36

1 Answers1

2

I did not try making the doskey permanent, but I just tried the following and it worked:

git init
touch test.txt
git add test.txt

to prepare my repo

doskey gc=git commit -m $*

to prepare the alias

now gc tells me that "switch m requires a value". To commit, it is now gc "testmessage"

I will edit why the $* works as soon as I know. I just remembered this from somewhere.

Similarly, you can use

doskey gcm=git commit -m "Message"

and then typing gcm will be that exact equivalent, always including "Message"

Edit: The $* was mentioned here, but I just tried and it seems like %* would work as well to catch all arguments. I'm still not sure what the difference between the two is, but it seems like $* works in the cmd and from a batch file, while %* only works from the cmd. Source is trying out - I couldn't find anything about this yet.

lucidbrot
  • 5,378
  • 3
  • 39
  • 68