Joseph Webber
Joseph Webber

Reputation: 2173

How can I create Windows shortcut commands for git?

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.

Upvotes: 2

Views: 1033

Answers (1)

lucidbrot
lucidbrot

Reputation: 6156

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.

Upvotes: 2

Related Questions