Phpstorm Use Git Bash



This blog post shows how to setup a fully dockerized development suite with PhpStorm, GIT and Postman. But what is development without debugging? If all apps are dockerized you will need a workaround to be able to debug the application e.g. with PhpStorm and Xdebug. This is also considered. If you not familiar with Dockerized desktop apps, check out the Dockerized introduction. You should create your own Docker images, but for testing my Docker images should work too. The bash scripts refer to a folder data/x11docker in your home directory where x11docker stores the container config. Please create it before.

  1. 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.
  2. Git 2.10+ Node.js 8+, npm 6+ Docker 18.03+ PHP 7+ and Composer 1.4+ Windows users: use Git Bash¶ Git Bash (part of Git for Windows) is required on Windows, please use it instead of cmd.exe / PowerShell for both interactive sessions and as your npm script shell.

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. The above steps can be easily adapted to any self hosted git server running on Linux, as well as to any product with git integration. A word about security. Having a self hosted git server is very useful and handy, however, in order to for it to be of any use, you will need to open an SSH port from the outside world to your NAS drive. 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.”.

Setup GIT

To work properly with Dockerized GIT you need three things. A Docker container with GIT, the mounted source of course and your SSH credentials.

Docker Image

Let's start with the GIT Docker image. The minimal packages are git and openssh.

Phpstorm

Start script

One cool thing of x11docker is, that it does all the heavy lifting. Don't worry about file permissions, how to share the ssh socket or to mount directories. All my sources are stored under data/sources. This makes it easy to mount the root source directory. I set the working directory to the current directory where the git command is executed. With this is feels like native GIT usage.

Create the following script named git and put it to a directory which is in your PATH variable e.g. ~/bin and make it executable.

Now you can use GIT as always and it works seamlessly. Ok, there are some small caveats. The start time is compared to native GIT long and you don't have bash completion. But I use PhpStorm mostly for VCS stuff.

If some SSH keys are not found, you can mount the ssh folder with --sharedir $HOME/.ssh:ro.

Setup PhpStorm

To work efficiently with Dockerized PhpStorm you will need a Docker container with PhpStorm and the same packages like in the GIT dockerfile.

Docker Image

PhpStorm can be downloaded and extracted to /opt. I use this method in my PhpStorm Docker image. You will need the packages git, openssh, vim, gnome-keyring and libsecret to work properly. PhpStorm stores connection credentials in the Linux keyring.

Start script

The PhpStorm script has some more options like git, because we need a clipboard for copy & paste and hostdbus for credentials. I use also hostdisplay but you can also try xpra. To debug applications with PhpStorm you must add PhpStorm to the network of the application which should be debugged. I use a trick in the PhpStorm startup script to add the phpstorm container to every default network.

You have to set the xDebug XDEBUG_CONFIG option to remote_host=phpstorm and ensure that xdebug.remote_connect_back is disabled. Read more about Docker PHP debugging.

Setup Postman

Postman is a popular tool for API development. It has many features like test, debug and documentation of your APIs.

Docker Image

Simply install Postman for your distro. That's it.

Start script

To interact with other Docker containers via a local domain you have to add the add-host option with the IP of your Docker network. In this example it's 172.17.0.1 but may be vary on your host. You can also share your Downloads folder to import / export Postman collections. Debugging your APIs with xDebug works like a charm.

Chromium

I use a dedicated Chromium for development with installed development plugins. Some plugins have access to all data of the webpage or can even manipulate the website data. To browse a development website which is served by a Docker container via a local domain you have to add the add-host option with the IP of your Docker network.

Phpstorm Terminal Use Git Bash

Conclusion

This blog post has shown how to setup a complete development environment with Docker. It's not very complicated but you have to figure out a few things. It's almost a native feeling and has so many benefits, such as: Run different versions of same application. The best thing is, that you not bloat your host system with other software.

PhpStorm includes an embedded terminal emulator for working with your command-line shell from inside the IDE. Use it to run Git commands, set file permissions, and perform other command-line tasks without switching to a dedicated terminal application.

Initially, the terminal emulator runs with your default system shell, but it supports many other shells such as Windows PowerShell, Command Prompt cmd.exe, sh, bash, zsh, csh Mozilla for mac os x. , and so on. For information about changing the shell, see Configure the terminal emulator.

Open the Terminal tool window

  • Select View | Tool Windows | Terminal from the main menu or press Alt+F12.

By default, the terminal emulator runs with the current directory set to the root directory of the current project. Google print for mac. You can change the default start directory in Settings/Preferences (Ctrl+Alt+S) | Tools | Terminal.

Phpstorm Use Git Bash Tutorial

Alternatively, you can right-click any file (for example, in the Project tool window or any open tab) and select Open in Terminal from the context menu to open the Terminal tool window with a new session in the directory of that file.

Start a new session

  • Click on the toolbar to start a new session in a separate tab.

To run multiple sessions inside a tab, right-click the tab and select Split Vertically or Split Horizontally in the context menu.

The Terminal saves tabs and sessions when you close the project or PhpStorm. It preserves tab names, the current working directory, and even the shell history.

To close a tab, click on the Terminal toolbar or right-click the tab and select Close Tab from the context menu.

Press Alt+Right and Alt+Left to switch between active tabs. Alternatively, you can press Alt+Down to see the list of all terminal tabs.

To rename a tab, right-click the tab and select Rename Session from the context menu.

To search for a certain string in a Terminal session, press Ctrl+F. This searches all text in the session: the prompt, commands, and output.

Configure the terminal emulator

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Tools | Terminal.

  2. Specify the desired shell to use with the embedded terminal emulator, change the start directory, and define environment variables among other settings.

    PhpStorm should automatically detect the default shell based on your environment. Here are some of the possible shells you might consider:

    • Bash: /bin/bash

    • Free internet browsers for mac. Z shell: /bin/zsh

    • Bash for Windows: bash.exe

    • WSL: wsl.exe

    • PowerShell: powershell

    • Command Prompt: cmd.exe

    • Cygwin: 'C:cygwinbinbash.exe' --login -i

The embedded terminal emulator also inherits the following IDE settings:

  • On the Keymap page, you can configure the copy Ctrl+C and paste Ctrl+V shortcuts.

  • On the Editor | General | Appearance page, you can configure blinking frequency for the caret. The Terminal does not inherit the Use block caret option because it always renders the caret as a block.

  • On the Editor | Color Scheme | Console Font page, you can configure line spacing and fonts.

  • On the Editor | Color Scheme | Console Colors page, you can configure font colors.

  • On the Editor | Color Scheme | General page, you can configure the selection foreground and background colors.

Run IDE features from the terminal

Instead of running a specific command in the integrated terminal and reading console output, you can use the relevant IDE feature, like a tool window or a dialog that implements this functionality. For example, the diff viewer actually runs the diff command in the system shell to produce results. Another example is the Log tab in the Git tool window, which is based on the output of the git log command.

Open the Log tab of the Git tool window from the terminal

  1. Type a supported command in the terminal and notice how it gets highlighted.

  2. Instead of pressing Enter, which runs the command in the terminal, press Ctrl+Enter to open the corresponding GUI element. In this example, it will open the Log tab of the Git tool window and filter commits for the docker branch.

If you want to disable this feature, click on the title bar of the Terminal window and clear the Run Commands using IDE option. Alternatively, clear Run Commands using IDE on the Tools | Terminal page of the Settings/PreferencesCtrl+Alt+S.