Execute commands from .bat file on Git Bash Terminal

I am newbie to Git bash.

Just out of curiosity trying to make a .bat file which contains commands(Dont know if Git Bash supports .bat file)

  • Deriving application build version from `git describe` - how to get a relatively straightforward string?
  • Show conflict diff part of a merge
  • Makefile for pulling and building projects
  • How to maintain independence of pull request branches in the face of shared code
  • What is the shortest way to swap staged and unstaged changes in git?
  • Add new local directory to a git remote branch
  • What I want to achieve is simply drag and drop this .bat file to Git Bash terminal
    and commands in the file get executed(Is it possible?).

    My commands in .bat file

    cd "C:\Users\USER\abc\xyz"
    cd "C:\Users\USER\abc\xyz\pqr"
    export HOME="C:\Users\USER\some_directory"
    export HOME2="C:\Program Files\directoy"

  • cannot load gems in test environment
  • How does --no-ff merge break bisect and blame?
  • Pushing untracked content with git
  • How to commit/push a Git tag with Gradle?
  • Error during creating my own pod with ObjectiveC
  • Fastest way to merge branches via gitlab (or git)?
  • 2 Solutions collect form web for “Execute commands from .bat file on Git Bash Terminal”

    Git Bash can execute bash scripts, but not bat scripts. If you rename the file to script.sh and rewrite like this, then Git Bash should be able to execute it:

    cd 'C:\Users\USER\abc\xyz'
    cd 'C:\Users\USER\abc\xyz\pqr'
    export HOME='C:\Users\USER\some_directory'
    export HOME2='C:\Program Files\directoy'

    I replaced the double quotes with single quotes. Otherwise the backslashes would be used as escape characters, for example Git Bash would try to execute cd C:UsersUSERabcxyz. Actually it’s better to write paths in Git Bash like this:

    cd '/c/Users/USER/abc/xyz'
    cd '/c/Users/USER/abc/xyz/pqr'
    export HOME='/c/Users/USER/some_directory'
    export HOME2='/c/Program Files/directoy'

    In any case, I think what you’re looking for is NOT “executing”, but “sourcing”. If you source this script, the commands will be executed in your current shell. So HOME and HOME2 will be set in your current shell. If you execute this, that will launch a new shell, which will execute the cd commands and set HOME and HOME2 but those settings won’t affect your current shell.

    It’s possible to create script.sh files and execute them by double clicking. But it is not possible to source them by double clicking, or to have them sourced by drag and drop to a Git Bash window.

    You can run batch files just from git bash


    From Out of a git console: how do I execute a batch file and then return to git console?

    Git Baby is a git and github fan, let's start git clone.