How to script git commands in a Windows bat script? [duplicate]

梦想的初衷 提交于 2019-12-23 02:25:31

问题


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:


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)



来源:https://stackoverflow.com/questions/41660025/how-to-script-git-commands-in-a-windows-bat-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!