Setup git in Intellij terminal - windows

I want to use git in Intellij Terminal but it does not recognize the command. In Command Prompt and Windows power shell the command in recognized (I added the git path in System Environment Variables). I am also aware that Intellij has an GUI integration with Git.
So, can anyone tell me how can I use the git command in the Intellij terminal.

Setup JetBrains(InteliJ, WebStorm, PHPStorm) IDE terminal to use GIT bash
File
Settings
(Enter 'Terminal' in search)
Change Shell path to:
"C:\Program Files\Git\bin\sh.exe" --login -i
or
"C:\Program Files\Git\bin\bash.exe"
If you have another directory for installed git change it respectively.

In the IDEA settings make sure that your terminal path leads to "usr/bin" instead of "/bin".
As a result you will see pretty rich console output:

For me, it works also but only the path of Git Bash has changed in Windows :
"C:\Users\REPLACE_THIS_BY_YOUR_USER\AppData\Local\Programs\Git\bin\sh.exe" --login -i

The full path is not needed anymore (windows), I just replaced cmd.exe to sh.exe and bingo was his name O
Settings > Tools > Terminal > Shell path > sh.exe

In my case, the Git Bash through IntelliJ had TERM=xterm-256color.
Regular Git Bash had TERM=xterm
To fix the garbled characters issue in IntelliJ Idea,
Go to "File | Settings | Tools | Terminal"
Environment Variables: TERM=cygwin
In IntelliJ Terminal, Shell Path I was using was already:
C:\Users\<userId>\programs\Git\bin\bash.exe --login -i

You don't need to reinstall anything. Go to:
File
Settings
Search for terminal
in shell path type: "C:\Program Files\Git\bin\sh.exe" --login -i (or another directory where you installed Git)

This worked for me:
IntelliJ:
File->Settings->Version Control->Git:
On the right side, Path to Git executable:
"C:\Program Files\Git\bin\git.exe"

Related

How can I use a git bash terminal profile in Visual Studio 2019?

Visual Studio 2019 has recently added a new (much-needed) terminal feature in its 16.6 version.
It's really great, but I'm having a hard time integrating git bash in the profiles.
I've tried a few variations of arguments and whatnot of the following profile:
But whenever I try selecting that profile, the terminal shortly displays a blank screen, then opens the default PowerShell terminal.
What am I doing wrong and how can I configure the profile correctly?
In case you haven't figured it out already: You need to add argument -i (to make the shell interactive), and I also recommend --login (to make the shell read default profile configuration files).
Try adding the following in the Arguments field:
--login -i
I used C:\Program Files\Git\bin\bash.exe as the Shell Location, and it worked fine.
Solution I am using while waiting for a better one:
Shell Location: C:\WINDOWS\system32\cmd.exe
Arguments: /k ""%VSAPPIDDIR%..\Tools\VsDevCmd.bat" & bash"
Essentially, I am launching cmd and running the "bash" command at launch, effectively nesting the bash terminal within cmd.
My Workaround:
What you no one mentioned in all of these replies is that you need the shell not the executable different things...
Shell Location: C:\Program Files\Git\bin\sh.exe
Arguments: (If you have any preferences add here, it works without)
And...
Walah!

How to setup Intellij idea terminal path with cmder but initiated with git bash.exe?

So I have installed both Cmder and Git bash, and my Cmder is setup in a way that to run git bash.exe inside.
Currently my Intellij idea's path for terminal is set to:
C:\Program Files\Git\bin\bash.exe, which works fine for bash.exe
However, one disadvantage for directly using bash.exe is that it will not automatically convert a windows directory, for example:
D:\Documents\Adobe, when I copy this after cd, it will be:
cd D:\Documents\Adobe instead of:
cd /d/Documents/Adobe which I will get in cmder.
I have looked up online, people shared about how to incorporate cmder in idea's terminal by using the path:
"cmd.exe" /k ""%CMDER_ROOT%\vendor\init.bat""
However, that is only using cmder as a coating for cmd.exe, not bash.exe as I want.
I have tried to replace with:
"C:\Program Files\Git\bin\bash.exe" /k ""%CMDER_ROOT%\vendor\init.bat"", it was not working.
also tried:
"C:\Program Files\Git\bin\sh.exe" --login -i /k ""%CMDER_ROOT%\vendor\init.bat""
and:
"C:\Program Files\Git\bin\sh.exe" /k ""%CMDER_ROOT%\vendor\init.bat""
All failed.
Any sugestons? Thanks!
Or if someone can show me how to change git bash.exe so that it can automatically translate the windows directory to Linux type, that would also work.
I don't think you can run git-bash in cmder AND from Intellij IDEA terminal.
I tried this: creating a task for git-bash in Cmder and try to use cmder.exe /TASK xxx in Intellij. I have the task, but it seems that Intellij does not support args after an executable in Terminal settings, so /TASK xxx is not parsable.
Then I changed path in Terminal settings to a BAT file, but terminal seems not support running it; I see terminal flashes and closes. Maybe only executable is allowed. Branch info is shown at the right of current path. I think it is convenient.
So, you have two options:
change terminal to git-bash.exe and get used to slash as path separator(and that is much saner than back slashes, trust me)
just configure Intellj Terminal to open cmder, with default task like this: cmd /k ""%ConEmuDir%\..\init.bat" ". This will open cmder in the current folder, and you also have git support. That is, stop using mingw64 and only ConEmu + clink. You have color support, Windows backslashes and so on. And you also can mix Win commands with bash syntax(with "Shell integration" ticked). This is what I am doing right now. Branch info is shown, lambda symbol as well. It is already perfect.

WebStorm mocha test 'sh' is not recognized as an internal or external command

I'm trying to run a mocha test for my node.js code which runs the following line:
exec(`sh ${scriptFile}`);
When I run it from the command line (Git Bash) using npm test, it passes. However, when I run it from WebStorm I get the following error:
'sh' is not recognized as an internal or external command,
operable program or batch file.
I feel like I'm probably missing some WebStorm setting, but I can't figure out what it is. Any ideas?
P.S. I'm on Windows.
For those who are using phpStorm on Windows and come here by Google
Install Git on your machine. Go to Settings/Terminal and set shell path to C:\Program Files\Git\bin\sh.exe
Also add C:\Program Files\Git\bin to your PATH in environment variables.
Git Bash implements a *nix-esque shell simulating bash which can parse your command. Webstorm appears to be trying to execute your command in either powershell or cmd, which do not support sh syntax.
Open the Terminal page of the Settings/Preferences dialog, and configure the Shell path field as follows:
"[path to the git installation]\bin\sh.exe" -login -i
This will probably be "C:\Program Files\Git\bin\sh.exe" -login -i
Source: https://www.jetbrains.com/help/webstorm/2017.1/working-with-embedded-local-terminal.html

Jenkins pipeline sh fail with "cannot run program nohup" on windows

I have windows 10 and I want to execute the sh command in the Jenkinsfile from Jenkins pipeline using bash for Ubuntu for windows, but it doesn't work
I have the following stage in my Jenkins pipeline :
stage('sh how to') {
steps {
sh 'ls -l'
}
}
The error message is :
[C:\Program Files (x86)\Jenkins\workspace\pipelineascode] Running shell script
Cannot run program "nohup" (in directory "C:\Program Files (x86)\Jenkins\workspace\pipelineascode"): CreateProcess error=2, Le fichier spécifié est introuvable
I tried changing Jenkins parameter->shell executable with
C:\Windows\System32\bash.exe
but same error...
how to run sh script using windows 10's bash?
From a very quick search, it looks like your error is related to the following issue : JENKINS-33708
The main cause looks like the sh step is not supported on the Windows. You may use bat or install Cygwin for instance.
Nevertheless two solutions were proposed in the previous link, suggesting you to do the following steps :
Install git-bash
Ensure the Git\bin folder (i.e.: C:\Program Files\Git\bin) is in the global search path, in order for Jenkins to find sh.exe
Make nohup available for Jenkins, doing the following in git-bash (adapt your paths accordingly) :
mklink "C:\Program Files\Git\bin\nohup.exe" "C:\Program Files\git\usr\bin\nohup.exe"
mklink "C:\Program Files\Git\bin\msys-2.0.dll" "C:\Program Files\git\usr\bin\msys-2.0.dll"
mklink "C:\Program Files\Git\bin\msys-iconv-2.dll" "C:\Program Files\git\usr\bin\msys-iconv-2.dll"
mklink "C:\Program Files\Git\bin\msys-intl-8.dll" "C:\Program Files\git\usr\bin\msys-intl-8.dll"
Depending on your installation you may have to use these paths :
mklink "C:\Program Files\Git\cmd\nohup.exe" "C:\Program Files\git\usr\bin\nohup.exe"
mklink "C:\Program Files\Git\cmd\msys-2.0.dll" "C:\Program Files\git\usr\bin\msys-2.0.dll"
mklink "C:\Program Files\Git\cmd\msys-iconv-2.dll" "C:\Program Files\git\usr\bin\msys-iconv-2.dll"
mklink "C:\Program Files\Git\cmd\msys-intl-8.dll" "C:\Program Files\git\usr\bin\msys-intl-8.dll"
With Git for Windows 2.16.2, I was able to add C:\Program Files\Git\usr\bin to the PATH (rather than C:\Program Files\Git\bin) and consequently my sh commands work in both FreeStyle and Pipeline builds. No mklink was necessary. (Source)
If you are executing on Windows, just change sh to bat. it will work as expected.
Example:
pipeline {
agent any
stages {
stage ('Compile Stage') {
steps {
withMaven(maven : 'apache-maven-3.6.1') {
bat'mvn clean compile'
}
}
}
}
}
With Git for Windows, I had to add C:\Program Files\Git\bin to the PATH environment variable of the slave node in Jenkins (to get access to sh), then add C:\Program Files\Git\usr\bin to the PATH locally on the Windows slave too (to get access to nohup).
Windows doesn't understand the "sh" command. To enable this, add
C:\Program Files\Git\bin &
C:\Program Files\Git\usr\bin
to the System Environment variable PATH, than restart your system.
Than execute your command in jenkins, it will work.
Switching sh to bat worked for me - I am running Jenkins on Windows. But only after I had resolved an issue caused by the fact I had not configured my tools (maven and the JDK) correctly in Jenkins either.
In my case I replaced 'sh' by 'bat' in Pipeline script and worked.
sh is not windows command. The simple way to enable the use of 'sh' command in windows is to install GIT BASH
Once you install GIT BASH, then you need to set below environment variables path.
C:\Program Files\Git\bin : This path contains sh.exe, bash.exe and git.exe
C:\Program Files\Git\usr\bin : This path contains several Linux based exe and dll (cat.exe, find.exe etc.)
By setting above configuration you will be able to execute 'sh' command in Jenkinsfiles on Jenkins installed on windows machine.
I was getting the same error below solutions worked for me..
Install git-bash
for windows use "bat" instead of "sh"
set "C:\Program Files\Git\usr\bin" to PATH(user variable)
My observation is that the agent seems to be trying to run nohup in the context where the agent.jar is run, not in the container. It didn't matter what I put in the container, the error message was the same. By putting nohup and sh in the PATH where the jenkins agent is running, I see a change in behavior.
git config core.sparsecheckout # timeout=10
git checkout -f c64c7bf905b6a4f5a8f85eb23bbd108f4c805386
sh: /home/jenkins/workspace/projname/simple_docker#tmp/durable-9fedc317/jenkins-log.txt: No such file or directory
sh: /home/jenkins/workspace/projname/simple_docker#tmp/durable-9fedc317/jenkins-result.txt.tmp: No such file or directory
mv: cannot stat '/home/jenkins/workspace/projname/simple_docker#tmp/durable-9fedc317/jenkins-result.txt.tmp': No such file or directory
I am seeing a folder /home/jenkins/workspace/projname/simple_docker#tmp/durable-9fedc317 which contains a file "script.sh" with the contents "docker inspect -f . repositoryname:tagname"
When this docker command is run manually on the command line, it always produces a single line of output consisting of a single period character. I have no doubt this is not what the jenkins system is looking for.
So you want the job running under WSL. If you want all jobs running under WSL have you considered installing Jenkins under WSL? Then everything is already in GNU land and you don't have to bridge the envrionment/culture of windows to GNU from within your Jenkins configuration.
I got the above issue in windows 10 and just added the path "C:\Program Files\Git\usr\bin" to the system variables then it started working.

How to set bash interpreter path in IntelliJ

I am wondering which path should be set in "Interpreter path" area in Run/Debug Configurations in IntelliJ, to complie and run bash script.
Using IntelliJ 15.0.3 on Windows 7
You must have a shell installed.
I have Git installed, so I use the path to the git shell.
Something like C:\Program Files\Git\bin\sh.exe.
I use also the --login -i flags for the "Interpreter options" field.
If you want to use the Windows CMD.exe you have to set:
Interpreter path: C:\WINDOWS\system32\CMD.exe (or wherever your cmd.exe is located)
Interpreter options: /C
Working directory: path/to/your/project
in the IntelliJ run config.
(Tested with IntelliJ 2017.3)
In Ubuntu,
Interrupter path can be set to: /bin/bash
On Windows 10 you can also use PowerShell.
Interpreter path: c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
Interpreter options: -Command
Working directory: path/to/your/project
For gitbash as your interpreter i found 2 ways
1.- For "BashSupport" plugin in intellij
Type Ctrl + Alt + S to go to settings
Search for Bash Support or go to "Languages & Frameworks->BashSupport"
In "Default Interpreter" put the path for gitbash
C:\Program Files\Git\bin\bash.exe
Then right click on the script to run and click on Edit script
Then click in "Use project interpreter"
Then in "Interpreter options" put
--login -i --
2.- For "Shell Script" plugin in Intellij
First set gitbash as your terminal
Ctrl + Alt + S to go to settings
Search for Terminal or go to "Tools->Terminal"
In "Shell path" put
C:\Program Files\Git\bin\bash.exe
Then Right click on the script to run and click on Edit script
Then in "Interpreter path" put
C:\Program Files\Git\bin\bash.exe
Then in "Interpreter options" put
-login -i --

Resources