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)

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"

  • git pull has to be invoked twice - halts after fetch, then performs only merge
  • git alias with bash conditional logic comparing strings - syntax issues
  • Git clone displaying errors and marking files as deleted in Windows 10
  • Error on Git Bash (Windows 7): sh.exe": android: command not found
  • Command to clear the Git Bash screen
  • How to get all branches with someone’s commits using git?
  • Update Author Name in all Commits in git after particular date
  • Why does git pull hang?
  • 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:

    #!/bin/bash
    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:

    #!/bin/bash
    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
    e.g.

     ./clear.bat 
    

    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.