Scripting Git Commands in Windows
Asked Answered
B

2

9

I have a few git commands I would like to automate in a restrictive windows environment. I find myself running these same commands over and over, executing in Git Bash.

$ git cd "R:/my/directory/repo"
$ git pull
$ git checkout "MyBranch"
$ git merge "MyOtherBranch"

and

$ git checkout "MyBranch"
$ git add .
$ git commit -m "My commit comments"

I'm proficient with JScript, and I know it works in my restrictive windows environment, so what I want to do is to start my day by opening the command prompt and typing

cscript.exe "MyGitRefreshScript.wsf" "MyBranch" "MyOtherBranch"

And then on demand, throughout the rest of the day, I can do that, and also use

cscript.exe "MyGitCommitScript.wsf" "MyBranch" "My commit comments"

Then I can sit there happily with the command prompt open pressing the up arrow and run those all day long as I do my work.

I can not install third party applications or tools on my machine, so I am looking to just use JScript inside a .wsf file to accomplish this. I would also like to be able to see the output messages like I do when running the commands in Git Bash as I do now.

Something like:

<job id="main">
    <script language="JScript">
        var sh = new ActiveXObject("WScript.Shell");
        sh.Run(Git.exe "SomeCommand" ?);

        //or

        var git = new ActiveXObject("Git");
        git.SomeCommand ???

        ...

Is this possible, and if so, how? Is there a clear alternative that doesn't involve some third party tool installation?

Thank you

Bouldon answered 18/12, 2014 at 4:16 Comment(0)
H
4

Is there a clear alternative that doesn't involve some third party tool installation?

Yes, git uses a bash shell which you can use in git alias, or in git script.

Even on windows, you can define a file name git-xxx, with a shell script in it (which will be interpreted by the bash from git).
The shebang of that script (again, even on Windows) will be #!/bin/bash.

In that script, you can use the git commands, and use the shell parameters ($1, $2, ...).

Humbuggery answered 18/12, 2014 at 7:1 Comment(2)
So a bash script is just like a .vbs file or .js file containing a script written VBScript or JScript? What is the language I write the bash script in?Bouldon
@Bouldon the language you would write the bash script in is... bash: en.wikipedia.org/wiki/Bash_%28Unix_shell%29. It is interpreted by the unix shell packaged with Git for Windows (msysgit), and will work even on Windows.Humbuggery
T
-3

Check this out -

http://nixkb.org/2014/08/git-made-easy-command-line-scripts-to-manage-git-changes-from-linux/

Here are two part scripts that you can run on any Linux box where git is configured for your local repos.

1) Initialize git or called gitInit.sh

2) Merge changes to git or called gitMerge.sh

Toenail answered 29/11, 2015 at 7:27 Comment(1)
Link is broken!Swashbuckler

© 2022 - 2024 — McMap. All rights reserved.