1

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
elmaystro
  • 117
  • 2
  • 7
  • @TonyHensler I used processBuilder to open the git bas, but cannot write commands on gitBash – elmaystro Jan 15 '17 at 11:55
  • I found an answer here [http://stackoverflow.com/questions/5401229/how-do-i-execute-several-git-commands-in-a-batch-file-without-terminating-after](http://stackoverflow.com/questions/5401229/how-do-i-execute-several-git-commands-in-a-batch-file-without-terminating-after) Thanks all!. – elmaystro Jan 15 '17 at 12:18

1 Answers1

4

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)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, but i am new to this so can you provide a one line example of this ? like how to do it for git commit or git add . ? – elmaystro Jan 15 '17 at 12:00
  • @elmaystro Sure: http://stackoverflow.com/q/8482843/6309: make sure to save that script as `git-xxx`, for instance `git-addc`, and you can call it with `git addc`. – VonC Jan 15 '17 at 12:27