Search code examples
windowsbashshgit-bash

Running a batch script containing 'git bash' commands without launching 'git bash'


I had a batch script on Linux which ran some 'git bash' commands when I launched it from a terminal. Now my Linux laptop is broken and then I lost this script and I don't remember its contents. I have a Windows machine now and I'd like to reproduce the equivalent script.

What I have been able to do is this script:

#!/usr/bin/env sh
eval "$(ssh-agent -s)"
ssh-add /c/Users/sdl96354/.ssh/id_ed25519_laustep
git add -A
git commit -m %1
git push

It does what I want but in order to run it I have to run 'git bash' first and then I have to type sh thisfile.bat "commit message". I would like to just type thisfile.bat "commit message" from an ordinary terminal, what should I do?


Solution

  • That's not a batch script but a shell script. You shouldn't name its extension as bat. Preferably name it with sh.

    The problem with your script is it uses %1 as a parameter "placeholder" a.k.a a positional parameter. Change it to "$1".