I've try to follow this question and sulution Git Bash in emacs on Windows I have this function:

(prefer-coding-system 'utf-8)
(defun git-bash ()
  (let ((explicit-shell-file-name "C:/Users/jankiewj/AppData/Local/Programs/Git/git-bash.exe")
        (explicit-bash.exe-args '("--login" "-i")))
    (call-interactively 'shell)))

but when I execute this function, git bash is created in new system window instead of Emacs window. So I don't even get the same error as OP.

I've also tried to run ansi-term but got error:

apply: Spawning child process: Invalid argument

How can I make git bash work inside Emacs window on MS Windows?

  • You could try running something like msys2.org and running both emacs and git (and bash) inside of it. It should make spawning shells easier.
    – user12563
    Jul 2, 2018 at 16:11

1 Answer 1


Follow the answer provided in: Git Bash in emacs on Windows

Most importantly, make sure that you are using bin/bash.exe rather than git-bash.exe.

You're good to use the defun apprach that you have in your question to make it work with an emacs command other than M-x shell (M-x git-bash in your case).

If you just want to change the shell that M-x shell uses, then you only need your init.el to have something like:

(prefer-coding-system 'utf-8)
(setq explicit-shell-file-name "C:/Program Files/Git/bin/bash.exe")
(setq explicit-bash.exe-args '("--login" "-i"))

The last important bit is that your ~/.bashrc (or other bash config file) should define a simpler PS1 for your prompt. This was the example given in the other answer:

if [ -n "$INSIDE_EMACS" ]; then
    export PS1='\[\033[32m\]\u@\h \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.