Windows 10, Git Bash - bash: git: command not found - windows

Git Bash no longer recognizes git commands, as well as some commands like ls and env. I've checked that the following paths were set up in my environment variables and I've tried uninstalling/reinstalling git.
Paths that are present:
C:\Program Files\Git\bin
C:\Program Files\Git\cmd
I would like to note that I am only having this issue with Git Bash. I've tried using git commands through Command Prompt, and everything seems to work there.

Related

Copy windows path into linux based terminals: Conemu, Cygwin, Git Bash

When I copy a windows path from windows explorer's location bar, C:\Users\Administrator\Links, it gets automatically translated to one of the following:
Cygwin in Conemu:
/mnt/c/Users/Administrator/Links
Git bash in Conemu:
/mnt/c/Users/Administrator/Links
Cygwin64 Terminal:
(no translation)
C:\Users\Administrator\Links
Git Bash on Windows:
(no translation)
C:\Users\Administrator\Links
But Cygwin actually wants C:/Users/Administrator/nextcloud/diary
or
/cygdrive/c/Users/Administrator/nextcloud/diary
and Git Bash actually wants /c/Users/Administrator/Links
So each time I try to cd into that directory, I get bash: cd: /mnt/c/Users/Administrator/Links: No such file or directory. Then I have to manually change the path.
Is there a way to change Conemu's "translation" rule? Do you experience the same problems when using linux terminals with/without Conemu? How did you cope with this?
Edit:
The Git Bash is started in Conemu by setting up a task with commands:
C:\Program Files\Git\git-cmd.exe --no-cd --command=usr/bin/bash.exe -l -i -new_console:t:"Git Bash"
and Cygwin is started in Conemu with commands D:\app\cygwin64\Cygwin.bat -new_console:t:"cygwin"
I ran into the same problem using Cmder (which uses Conemu).
In the launch options (in Cmder, it's in Startup - Tasks), you must select the task (for example bash :: bash) and add:
-cur_console: m: "".
Indeed, according to the documentation:
https://conemu.github.io/en/NewConsole.html#syntax
in the options of -cur_console, we can read:
m: / mnt - defines ‘/ mnt’ prefix for Unix-path conversion, m: "" - no
prefix

Git bash: whereis command not found

I am using git bash on a windows machine. Everything works normally except for the whereis command. The terminal tells me the command is not found:
$ whereis grep
bash: whereis: command not found
I have already tried adding C:\Program Files(x86)\Git\bin to my PATH.
How do I fix this?
Use the where in Windows
Utilized the command whereis in Linux is equals that command where , provided for the Windows kit for Windows 98, and is included by default in Server 2003, Vista, and newer versions :
$ where git
C:\Program Files\Git\mingw64\bin\git.exe
C:\Users\MyUser\scoop\shims\git.exe
More information
Equivalent whereis in Windows
where.html
Add the .exe in gitbash for Windows
While you want an executable of the type .exe in gitbash you should be add in the follow path relation :
C:\Program Files\Git\mingw64\bin\<EXE>.exe
Or where there is ubication the folder git but always should be add in mingw64\bin\.
Install whereis in Windows
You must download the following file:whereis.zip
Once unzipped, you should copy the whereis.exe file that is in :
mvp_tips/whereis/Debug/
And copy it in :
C:\Program Files\Git\mingw64\bin\
If all went well, close all the GitBash tabs and reopen one of them and enter :
$ whereis whereis
C:\Program Files\Git\mingw64\bin\whereis.exe #And what should come out if everything is correct:
Script for download and installation
Run the Git Bash as Run As Administrator
#!/bin/bash
wget www.flounder.com/whereis.zip
unzip whereis.zip
cd mvp_tips/whereis/Debug/
cp whereis.exe 'C:\Program Files\Git\mingw64\bin\'
source ~/.bashrc
whereis whereis

msysgit Git Bash ignores 1 entry in my PATH variable

The Problem
When I enter the command android in the normal Windows command prompt, android.bat is launched from the a directory I included in the PATH-variable.
When I enter the same command in the msysgit Git Bash, the bash complains:
sh.exe": android: command not found
android is the only command that has this problem, all others work on both shells (the directory it is contained in is android-sdk/tools )
Working examples are node, npm, heroku.
My environment
This is what echo $PATH returns in Git Bash:
/c/Users/Tobias/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Users/Tobias/AppData/Local/apache-ant-1.9.4/bin:/cmd:/c/Program Files/nodejs/:/c/Python27:/c/Python34/:/c/Python34/Scripts:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (x86)/ATI Technologies/ATI.ACE/Core-Static:/c/Program Files (x86)/Common Files/Acronis/SnapAPI/:/c/Program Files (x86)/Heroku/bin:/c/Program Files/Java/jdk1.8.0_11/bin:/c/Ruby200-x64/bin:/c/Users/Tobias/AppData/Roaming/npm:/c/Users/Tobias/AppData/Local/Android/android-sdk/tools:/c/Users/Tobias/AppData/Local/Android/android-sdk/platform-tools:.
This is what echo %PATH% returns in Windows CMD:
C:\Users\Tobias\AppData\Local\apache-ant-1.9.4\bin;C:\Program Files (x86)\git\cmd;C: \Program Files\nodejs\;C:\Python27;C:\Python34\;C:\Python34\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files (x86)\Heroku\bin;C:\Program Files\Java\jdk1.8.0_11\bin;C:\Ruby200-x64\bin;C:\Users\Tobias\AppData\Roaming\npm;C:\Users\Tobias\AppData\Local\Android\android-sdk\tools;C:\Users\Tobias\AppData\Local\Android\android-sdk\platform-tools;
Seems like msysgit can't access files inside C:\Users\x\AppData\Roaming.
I fixed the issue by moving the directory directly in the C: drive.

Git Bash how to show info about repo files like in Git Shell

I`m working with Git Bash on Windows. But before, I was working with Git Shell (from github). In Git Shell was this really awesome thing, See the image below:
In Git Shell, I do not need to use git status to see how many untracked, changed or deleted file I had. Git Shell shows that information after any command.
How can I do this for Git Bash (on Windows)?
You can simply manipulate the PS1 variable, something like this might help you:
$ PS1="$PS1 [`git diff --shortstat`]> "
The result should be something like this:
rlegendi#localhost /.../gitrepo (master)
[ 1 file changed, 3 insertions(+)] >
So basically you have to add this like to your profile file (either at the Git installation directory typically under c:\Program Files (x86)\Git\etc or in your home directory). That way you can create a bit nicer version.
Take a look on PROMPT_COMMAND and different git diff switches (like --numstat, etc.).

Git with SSH on Windows

I've went through the excellent guide provided by Tim Davis which is about configuring Git to work with SSH under Windows in order to produce a Git Server in order to have a main place for my DVCS.
I am in the process of creating a clone for my project. I’ve went through all the steps till this point, but I keep getting this from TortoiseGit:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
bash: Administrator#127.0.0.1: command not found
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
Success
and nothing gets cloned.
BTW: The TortoisePLink comes up just before this message appears and asks me: “login as:” ( I thought that this info is given in the command, i.e: Administrator#blahblah.
My home variable is set to the correct place:
From a Git Bash shell:
echo $HOME
/c/SSH/home/Administrator
I’ve also tried using Putty’s plink instead of TortoisePLink (in both Git’s and TortoiseGit’s installation). This time the error was narrowed down to:
git.exe clone -v “ssh://Administrator#127.0.0.1:22/c:/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
I fought with this problem for a few hours before stumbling on the obvious answer. The problem I had was I was using different ssh implementations between when I generated my keys and when I used git.
I used ssh-keygen from the command prompt to generate my keys and but when I tried "git clone ssh://..." I got the same results as you, a prompt for the password and the message "fatal: The remote end hung up unexpectedly".
Determine which ssh windows is using by executing the Windows "where" command.
C:\where ssh
C:\Program Files (x86)\Git\bin\ssh.exe
The second line tells you which exact program will be executed.
Next you need to determine which ssh that git is using. Find this by:
C:\set GIT_SSH
GIT_SSH=C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe
And now you see the problem.
To correct this simply execute:
C:\set GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
To check if changes are applied:
C:\set GIT_SSH
GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe
Now git will be able to use the keys that you generated earlier.
This fix is so far only for the current window. To fix it completely you need to change your environment variable.
Open Windows explorer
Right-click Computer and select Properties
Click Advanced System Settings link on the left
Click the Environment Variables... button
In the system variables section select the GIT_SSH variable and press the Edit... button
Update the variable value.
Press OK to close all windows
Now any future command windows you open will have the correct settings.
Since this keeps coming up in search results for making git and github work with SSH on Windows (and because I didn't need anything from the guides above), I'm adding the following, simple solution.
(Microsoft says they are working on adding SSH to Visual Studio, and GitHub for Windows still doesn't support SSH...)
1. I installed "git for Windows" (which includes ssh and a bash shell)
https://git-scm.com/download/win
2. From the included bash shell (which, for me, was installed at: C:\Program Files\Git\git-bash.exe)
cd to the root level of where you want your repo saved (something like: C:\code\github\), and
Type:
eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"
3. Type: (the SSH link from the repo)
git clone git#github.com:RepoName/Project.git
you are using a smart quote “ instead of " here:
git.exe clone -v “ssh://
^^^
Make sure you use the plain-old-double-quote.
I've found my ssh.exe in C:/Program Files/Git/usr/bin directory.
If Git for windows is installed, run Git Bash shell:
bash
You can run ssh from within Bash shell (Bash is aware of the path of ssh)
To know the exact path of ssh, run "where" command in Bash shell:
$ where ssh
you get:
c:\Program Files\Git\usr\bin\ssh.exe
I was trying to solve my issue with some of the answers above and for some reason it didn't work. I did switch to use the git extensions and this are the steps I did follow.
I went to Tools -> Settings -> SSH -> Other ssh client
Set this value to C:\Program Files\Git\usr\bin\ssh.exe
Apply
I guess that this steps are just the same explained above. The only difference is that I used the Git Extensions User Interface instead of the terminal. Hope this help.
When I typed where ssh it showed me multipe ssh.exe
user#pc MINGW64 /c/dev/
$ where ssh
C:\Users\user\AppData\Local\Programs\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe
Deleting / moving these exe helped:
# copy from
# C:\Users\user\AppData\Local\Programs\Git\usr\bin
# to something like
# C:\Users\user\AppData\Local\Programs\Git\usr\bin\backup-ssh
ssh-agent.exe
ssh.exe
ssh-add.exe
This solved the issue for me.

Resources