1

I would like to be able to type into my cmd or powershell this command and it automatically do a commit with a message like this

commit "Finished amazing feature"

and it would execute this

git add .; git commit -m "Finished amazing feature"; git push

But when I tried to add this alias it is giving me some error and not working, what am I doing wrong?

doskey commit=git add .; git commit -m "$1"; git push

error: switch `m' requires a value

4
  • Have you tried without the quotes, so git -m $1? Commented Nov 6, 2020 at 11:29
  • @aschipfl yes then the error was git: 'add.;' is not a git command Commented Nov 6, 2020 at 12:05
  • I would not recommend this as you have no chance to see what you are about to push Commented Nov 6, 2020 at 12:11
  • Oh, yes, I missed the wrong command separator ;, it is & in cmd and $T in doskey macros… Commented Nov 6, 2020 at 13:07

1 Answer 1

1

In PowerShell, an alias is just another name for a command. But you can create your own command, namely a function:

function commit ($message) {
    git add .
    git commit -m $message
    git push
}

Add that function to your PowerShell $profile. It will then be automatically loaded into your session when you start PowerShell.

It is called just like you wanted:

commit "Finished amazing feature"
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, how would you do the same for cmd?
Found it DOSKEY commit=git add . $T git commit -m $1 $T git push In cmd the seperator command is $T
@Liga You can add the cmd version as additional answer to your own question. If someone else needs this. I would never do any new things in cmd though, it's more or less crappy legacy tool every since powershell arrived.

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.