How to script git commands in a Windows bat script

2019-06-09 23:55发布

This question already has an answer here:

I want to create a bat script that do the following :

  • opens git bash

  • run commands on git bash (ex. git init, git add ., ...)

Context: I am working on an idea, that I will access git-bash through java.
I use Netbeans IDE

1条回答
\"骚年 ilove
2楼-- · 2019-06-10 00:25

You don't have to open git bash at all to execute a sequence of git commands in a script:

Create your bash script as any other script:

#!/bin/bash
git ...
#other commands

Save it as git-myscript (no extension) anywhere referenced by your $PATH or %PATH% (this works even on Windows)

Run it with git myscript: it will be executed by the git bash.

This work for any file named git-xxx: you can call that file as a bash script with git xxx.
(on Linux, Mac or Windows)

查看更多
登录 后发表回答