You can create a batch file (.bat) with the following content:

"C:\Program Files\Git\git-bash.exe" -c "python myScript.py"

Yu can also make this available for all .py file by editing your regedit as explained here: Adding a context menu item in Windows for a specific file extension with the following command:

"C:\Program Files\Git\git-bash.exe" -c "python \"%1\""
🌐
Stack Overflow
stackoverflow.com › questions › 56943673 › how-to-run-git-bash-commands-in-python
How to run git bash commands in python? - Stack Overflow
I run the following command in git bash terminal (not the windows command line or mac's terminal). Copyssh username@code.companyname.com -p 12356 gerrit query --format=JSON --current-patch-set --files change: 878545 · This generates a JSON output when I run it in git bash. I am trying to do the same in Python file using the following:
Discussions

windows - Python not working in the command line of git bash - Stack Overflow
Python will not run in git bash (Windows). When I type python in the command line, it takes me to a blank line without saying that it has entered python 2.7.10 like its does in Powershell. It doesn't More on stackoverflow.com
🌐 stackoverflow.com
Python 3 won't run from the Git Bash command line - Stack Overflow
Basically, I type python into Git Bash command line and I get back a blank line as if the command line is thinking... I've done plenty of research but I can't seem to run python on Git Bash by typi... More on stackoverflow.com
🌐 stackoverflow.com
June 1, 2019
git - Run bash command line script in python - Stack Overflow
Is it possible to run a command line bash script in python? I know of subprocess.call/check_output to run a single command with parameters. However, how do I run for tag in `git branch -r | grep "... More on stackoverflow.com
🌐 stackoverflow.com
why does the python command not work in gitbash app windows??
Interesting. I just tried on my Windows 11 Pro setup, which I had forgotten had gitbash installed. This is how it went: user@computer MINGW64 ~ $ py --version Python 3.13.2 user@computer MINGW64 ~ $ python --version Python 3.13.2 user@computer MINGW64 ~ $ python3 --version Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Apps > Advanced app settings > App execution aliases. user@computer MINGW64 ~ $ which python /c/Python313/python user@computer MINGW64 ~ $ which py /c/Windows/py user@computer MINGW64 ~ $ More on reddit.com
🌐 r/learnpython
5
0
May 12, 2025
🌐
Medium
medium.com › @presh_onyee › getting-python-shell-to-work-on-git-bash-windows-mac-linux-5fdfc49409e4
Getting Python Shell To Work on Git Bash — Windows, Mac, Linux. | by Presh Onyee | Medium
April 14, 2019 - To solve this, simply type in winpty python in Git Bash or you can also type python -i Both of these commands will activate the Python shell.
Top answer
1 of 16
553

Temporary solution

Just enter this in your git shell on windows - > alias python='winpty python.exe', that is all and you are going to have alias to the python executable. This alias will be valid for the duration of the shell session.

winpty is a Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs.

Permanent solution

Add the command to your .bashrc in the users home directory. You can use the CLI or a text editor:

Using CLI

This can be accomplished from git bash like so:

echo "alias python='winpty python.exe'" >> ~/.bashrc

which will create .bashrc in the current users home directory if the file doesn't exist or append the alias to the end of .bashrc if it does.

Using a text editor

Alternatively, you could first create a .bashrc. Depending on your file manager, this may be easier to accomplish in git bash like so:

cd ~
touch .bashrc

At which point you can open .bashrc in your prefered text editor and add it there.

To apply the change, either use the command source .bashrc or restart the shell.

Update

Newer versions of Git no longer use .bashrc but instead use .bash_profile. Conda also uses this profile when initializing, so be sure not to overwrite or delete the initialization block. See more here: Git for Windows doesn't execute my .bashrc file.

2 of 16
132

I don't see next option in a list of answers, but I can get interactive prompt with "-i" key:

$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55)
Type "help", "copyright", "credits" or "license" for more information.
>>> 
🌐
Medium
prishitakapoor2.medium.com › configuring-git-bash-to-run-python-for-windows-a624aa4ae2c5
Configuring Git Bash to Run Python [For Windows] | by Prishita Kapoor | Medium
July 6, 2021 - Next, enter this command to tell Git Bash where to find the Python executable file. echo 'alias python="winpty python.exe"' >> .bashrc · This is an extra step that’s needed for users running Python in Git Bash.
🌐
Codegive
codegive.com › blog › how_to_run_python_file_in_git_bash.php
How to run python file in git bash
To run a Python file, you use the python command followed by the name of your script. ... Your script will start running, and you'll see its output. When it asks for input, type your response and press Enter. python my_script.py # Expected output: # Hello from Git Bash!
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › python › python run bash command
How to Run Bash Command in Python | Delft Stack
March 11, 2025 - The subprocess module is the most common way to run bash commands in Python. It provides a powerful interface for spawning new processes, connecting to their input/output/error pipes, and obtaining their return codes. This method is particularly effective when you want to run Git commands and capture their output for further processing.
🌐
GitHub
gist.github.com › nathania › 2840185
Execute git command from Python script · GitHub
May 2, 2014 - I made a git command in python, http://goo.gl/JUHJjc would you like to have some comments on it, I am going to do a version using gitPython API which i discovered after I was all done with the one using subprocess, however still debating which approach is better !
🌐
NSF NEON
neonscience.org › resources › learning-hub › tutorials › setup-git-bash-python
Install Git, Bash Shell, Python | NSF NEON | Open Data to Understand our Ecosystems
April 2, 2026 - This page outlines the tools and resources that you will need to install Git, Bash and Python applications onto your computer as the first step of our Python skills tutorial series. Checklist Detailed directions to accomplish each objective are below.
🌐
Reddit
reddit.com › r/learnpython › access python scripts globally, also with git bash
r/learnpython on Reddit: Access Python scripts globally, also with Git Bash
September 23, 2024 -

I managed to create a folder in Windows in which I store my Python scripts. I can then simply start these files using the command prompt:

Example:

d:\scripts\hello.py

Command Prompt:

C:\>hello.py
hello

I also installed "Windows Terminal" and Git. During the Git installation I clicked "Add a Git Bash Profile to Windows Terminal".

When I start Terminal and enter hello.py in the Git Bash as above, I get the following error message:

$ hello.py
/d/scripts/hello.py: line 1: syntax error near unexpected token `"hello"'
/d/scripts/hello.py: line 1: `print("hello")'

$ hello
bash: hello: command not found

Top answer
1 of 1
7

This is a known issue for windows 10. GitBash's terminal has issues with windows-native apps, such as python, powershell, ipython, etc.

  • The terminal eats events, such as your screenshot. This breaks ctr+c / ctrl+z events, preventing exiting
  • In addition, those apps break cursor movement, massively corrupted the shell.

The solution is to run winpty, which you should already have from git-bash. Now git-bash is able to run apps without issues.

$ winpty python -i

This fixes both python -i, ipython -i, powershell. I use the following aliases:

alias ipython='winpty ipython'
alias python='winpty python'
alias node='winpty node'
alias powershell='winpty powershell'

An alternate solution is to use a different terminal, such as Windows Terminal

Recently windows released a new Windows Terminal

Now it supports all bash apps, full utf-8 support (the best of any Windows terminals I've ever seen, 256+ ANSI colors, etc.) You no longer need winpty.

Edit your JSON config to use:

"commandline" : "ipython.exe"

If you are using python -i at all, check out ipython.

Combine that with winpty or the terminal to run ipython. It's a huge upgrade to quality of life and usability.

It adds a lot.

  • get function signatures and docs using foo? and foo??
  • copy->paste works.
  • quality of life using any statements longer than one line are hugely improved
  • syntax highlighting, even matches braces
  • tab completion of names and inspection of attributes such as:
x = "hi world"
x.<tab> # all `str` methods pop-up.

# or
import time
time.monotonic?

Get it using

python -m pip install ipython
🌐
Stack Overflow
stackoverflow.com › questions › 73625688 › from-python-run-python-script-in-git-bash
windows - From python, run python script in git-bash - Stack Overflow
I would use subprocess.run (or) subprocess.call within git-bash. ... Note: git-bash has nothing to do with Git, it's just included with Git-for-Windows. It's just a port of bash to Windows. Git needs (or needed in the past, and still wants) a POSIX-compatible shell, so it comes with bash. ... If you just start a python.exe process from your script, it's not going to just have a git-bash terminal attached.
🌐
Sonal Satpute
sonalsatpute.wordpress.com › 2016 › 07 › 21 › python-on-windows-git-bash
Python On Windows Git Bash – Sonal Satpute
July 26, 2016 - Follow below steps to enable Python from Windows Git Bash. Assuming you already installed Python on C:\Python27\ if not then please install the Python from here Open the Git Bash and follow bellow steps sonal@sonal-pc MINGW64 ~ $ export PATH="$PATH:/c/Python27" This will tell bash where to find Python. sonal@sonal-pc MINGW64 ~ $ python --version Python 2.7.12 It…