Phpstorm Use Git Bash



  1. Intellij Use Git Bash Terminal
  2. Intellij Use Git Bash
  3. Phpstorm Terminal Use Git Bash

Video tutorial on the Git integration in PHPStorm. I walk you through all the need to know features that come with PHPStorm.This video is part of an article.

I’m one of the rare Windows users at Automattic but thanks to the introduction of Windows Subsystem for Linux, my life is way easier. I can now run pretty much any Bash script without having to spin up a virtual machine like I used to have to. While it’s possible to build Node.js-powered projects natively under Windows thanks to the Windows-Build-Tools package, it’s a lot easier to just do everything within Linux. This is largely because building in one environment means that you can’t run the tools in the other environment.

  1. Now that you have Git authentication working within Linux, it’s time to get PhpStorm (or whatever IDE you use) to use Linux’s Git. The trick here is instead of having PhpStorm use git.exe, you need to point it at a batch script. This Stack Overflow question helped me a ton, but I needed to modify it a little bit.
  2. Access bash in the php-cli container: docker-compose run -rm php-cli /bin/bash; Install Composer, by following the download instructions for Linux; Still, inside the container, install dependencies: php composer.phar install; Exit the container exit; Note: In Linux, using the second method Composer will create the vendor folder as root!
  3. I installed git-bash Win 10, and that works fine too. I tried both the native and built in git inside PhpStorm and it works fine until I push. I am using username and password for github auth inside PhpStorm, and testing it succeeds, but when I try to push, it fails with “failed to read from the remote repository.”.

The main time that this bites you is when the project you’re working on has a pre-commit hook in Git. If you build your project in Linux but attempt to commit from Windows, it won’t work. IDEs such as PhpStorm do all of their Git operations from Windows. This blog post will explain how to get it to use the copy of Git within Linux.

Intellij Use Git Bash Terminal

  1. Install Pageant from PuTTY or if you’re signing your commits, then Gpg4win (its gpg-connect-agent can be set to be PuTTY compatible). Have it start with Windows in order to load your SSH keys.
  2. Verify that the agent is working by using PuTTY to connect to github.com with the username git. GitHub won’t let you open a shell but it’ll let you know that you have successfully authenticated. Note that command line ssh won’t work because it’s not Pageant-compatible.
  3. Install weasel-pageant to allow you to use SSH keys from within Linux.
  4. Verify that the agent is working by running ssh-add -l in Linux. Your key(s) should be listed.
  5. Verify SSH is working by running ssh git@github.com. If it doesn’t work, append -vvv to the end of the command to enable debug output to see what’s wrong.

Intellij Use Git Bash

Now that you have Git authentication working within Linux, it’s time to get PhpStorm (or whatever IDE you use) to use Linux’s Git.

The trick here is instead of having PhpStorm use git.exe, you need to point it at a batch script. This Stack Overflow question helped me a ton, but I needed to modify it a little bit.

Phpstorm Terminal Use Git Bash

For whatever reason, my .bashrc file wasn’t being loaded when calling bash.exe -c which meant that agent wasn’t being loaded. So as a part of my batch script, I’m manually loading my personal file that contains my shell customizations. Here’s my full batch file:

In PhpStorm, go to File → Settings (or Default Settings) → Version Control → Git and set the “Path to Git executable” to point at the batch file. Verify that it works by clicking the Test button.

Bash

With that, everything should work now!

Questions? Problems? Leave a comment below.