How to change the command base in Git Bash in VS Code? - bash

I'm learning to use Git. After installation I can open a Bash terminal on VS Code (I'm using Windows if that's relevant). Right after opening a Bash terminal, this command shows up automatically (the id and path are masked for privacy):
myid#machineid MINGW64 /c/Users/...
$ source C:/ProgramData/Anaconda3/Scripts/activate base
(base)
I guess it means it's using Anaconda to run the Git command. However, it appears many CMD commands that otherwise work normally in a Windows terminal don't work. For example, I can't create a new folder. This error comes up:
$ mkdir test
bash: /c/ProgramData/Anaconda3/Library/usr/bin/mkdir: Permission denied
(base)
Similarly, commands like ls or touch just don't work. But I find pwd works. I look at /c/ProgramData/Anaconda3/Library/usr/bin and see there are a bunch of CMD command exe files in there, such as mkdir.exe, rm.exe. I also look at the Git installation directory and find a folder with similar exe commands (C:\Program Files\Git\usr\bin)
On the other hand, I can still use Git commands. So this works (after manually creating the folder test):
$ git init
Initialized empty Git repository in C:/Users/.../test/.git/
(base)
Also, if I don't use VS Code, but use a Git CMD then everything works just fine.
So the question is how I can fix it? More specifically, how can I direct Git to use Git command base in VS Code instead of depending on Anaconda base? What it currently means to me is that if I uninstall Anaconda then Git may not work in VS Code at all.

Related

Adding gitbash to windows cmd to run make files

i have a windows machine that i installed git on it . on install i checked the add the gitbash to environment but after install when i run a smiple command like ls in my windows cmd i get the error
'ls' is not recognized as an internal or external command,
operable program or batch file.
now this is my env variables on my windows
the second one was added by git automatically on install but I add the first one by searching on stack overflow but none of them seems to work .
Extra Details :
in case you want to know what trouble it cause me . i am running some make commands that works properly on my gitbash but on my goland terminal it gives this error
./scripts/fmt.sh provider
process_begin: CreateProcess(NULL, sh C:\Users\farsh\go\src\gojeh\scripts\fmt.sh provider, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:16: run] Error 2
TL;DR
Git for Windows deliberately only puts the bare minimum on your Windows PATH
Details
If you look at the git\bin directory, you'll see that only git, bash and sh are there. Then there's a git\usr\bin directory will the standard *nix-style utilities you're expecting, including ls, although not including make on my machine. Those are not added to your Windows path, because many of them would conflict with the standard Windows utilities, and shadowing them could have unpredictable effects on other stuff running in Windows.
So you'll find the extra stuff is only visible when you're running inside Git Bash itself, where they're expected to work the *nix way.
If you need make for your system, you should probably install a version intended to be used on Windows.

How to get docker 'objects' completion on mintty-bash from git for windows

I have read (and tried) this:
https://docs.docker.com/machine/completion/
But it seems this is not the right way to get it on.
Anybody know how to get docker completion commands in Mintty (from Git for windows) bash command line?
Not sure if this is the best way to do this or if it work properly at all, but it seems to work!
Let me know if you find any strange behavior...
Minimum requirements:
Git for Windows (git bash / mintty terminal)
7-Zip or similar to extract files
Installation:
First of all, you will need the bash-completion package.
I discovered that the package built for cygwin works.
Choose a cygwin mirror: https://cygwin.com/mirrors.html
Navigate to: /cygwin/noarch/release/bash-completion/
Download: bash-completion-2.7-1.tar.xz
Extract it elsewhere
Copy the etc and usr folder to C:\Program Files\Git (see the note below)
Done, now you should have command completion enabled.
Testing:
You can test it by opening a git bash terminal and typing:
curl --ver (hit tab twice)
It will suggests something like this:
$ curl --ver
--verbose --version
Docker commands:
Now, about that docker commands...
I have found my files here:
docker command:
https://github.com/docker/docker-ce/blob/v17.09.0-ce/components/cli/contrib/completion/bash/docker
docker-compose command:
https://github.com/docker/compose/blob/1.16.1/contrib/completion/bash/docker-compose
docker-machine command:
https://github.com/docker/machine/blob/v0.12.2/contrib/completion/bash/docker-machine.bash
Just download and copy them to:
C:\Program Files\Git\usr\share\bash-completion\completions\
Make sure they are correctly named (remove the filename extension if any).
It should be named like this:
docker
docker-compose
docker-machine
No extra .txt or whatever...
Some notes:
I'm not sure if the package bash-completion-2.7.1 is the best version to work with git bash, I just got the latest one. (You can compare them and find it out)
You don't need to copy all the files from /usr/share/bash-completion/completions/, just the ones you want. (I didn't copy any of them).
It's a good idea to run a docker version, docker-compose version, docker-machine version and check the versions you are running, then download the correct files from the repository. (Choose the correct release tag for you).

Installing Heroku Toolbelt on Windows 10

I've been having some issues installing the Heroku toolbelt on Windows 10, 64-bit.
It's the first time I install Heroku. I downloaded it from https://toolbelt.heroku.com/windows.
After installing, I tried launching a new Git Bash and typing heroku login but what I got back was bash: heroku: command not found
Running the same command on Windows Powershell, what I got back was
'MYSQL' is not recognized as an internal or external command,
operable program or batch file.
'MYSQL' is not recognized as an internal or external command,
operable program or batch file.
Any suggestions? I thought that googling those lines would help, but I haven't found much.
I followed the recommendation from here, but now when typing heroku login on the Powershell, nothing happens. Nothing changes on the Git Bash.
I checked, and the Heroku folder was added to the PATH.
I thought I'd ask for some help before installing anything else.
Thank you!
bash: heroku: command not found
The error message is clear: Bash cannot find the heroku command, it's not on your PATH.
I checked, and the Heroku folder was added to the PATH.
It seems you didn't check it correctly.
Note that even if it looks correct in the PATH settings window,
Git Bash might have a different PATH configured.
To see the PATH in Git Bash, run:
echo $PATH
When debugging path issues,
it's best to first run heroku with the absolute path. For example if it's in C:\Program Files\Heroku\bin\heroku then you can run in Git Bash with:
/c/Program\ Files/Heroku/bin/heroku login
If this works (and it should),
then you can add it to PATH like this:
PATH="$PATH:/c/Program\ Files/Heroku/bin"
Note that Heroku will likely need other programs too on the PATH,
such as MySQL and Ruby.
Find their absolute paths,
and add there directories to PATH the same way as heroku itself in the above example.
If instead of Git Bash,
you want to work in CMD,
the procedure is the same,
but the syntax to print and set PATH is different:
echo %PATH%
set PATH="C:\Program Files\Heroku\bin;%PATH%"
In windows bash instead of this
PATH="$PATH:/c/Program\ Files/Heroku/bin"
use this
PATH="$PATH:/c/Program Files/Heroku/bin"
My working solution (for git-bash especially) is:
alias heroku='winpty `where heroku.cmd`'
stored in .bashrc in home user dir
and them
heroku
works as expected
If using bash from VSCode, I had to restart VSCode, after installing heroku. If not using VSCode, you probably need to restart your bash terminal, after installing heroku.
In Control Panel\All Control Panel Items\System (if you are using Windows), go to Advanced system settings, and there in Environment Variables, you'll find two lists, on the same window, viz. System variables, and User variables for your system. Make sure you add your path, viz. C:/Program Files/Heroku/bin, in both of these lists.
I know this is an old thread and just want to share my solution.
Edit .bashrc for git-bash
alias heroku='"C:\Program Files\Heroku\bin\heroku.cmd" $#'

Commands don't work in Git bash but work in Windows command

I installed Ruby, and I installed git.
When I right-mouse click, I can run Git bash.
But commands like
git status
or
gem install ~~~
don't work there. But they perfectly work fine with Windows command.
But commands like
heroku login
doesn't work both in windows command and git bash. I get the error message
bash: heroku: command not found
Is there something that I need to connect git bash with these commands?
1.9.5 is now obsolete.
Uncompress PortableGit-2.5.0-64-bit.7z.exe anywhere you want, and add C:\path\to\PortableGit-2.5.0-64-bit\bin to your %PATH%.
Also, call C:\path\to\PortableGit-2.5.0-64-bit\git-bash.exe to test a bash session, in which git will be recognized.
Make sure your %PATH% also includes the path for ruby.

Adding Git to PATH Variable - Can't find GitHub under AppData/Local

I was following this guide here on how to add Git to my Path variable so I can use it from the command line (Not just Git Bash).
Installing Git in PATH with GitHub client for Windows
To quote an answer, Git was supposedly located here
Get the Git URL
We need to get the url of the Git \cmd directory your computer. Git is
located here:
C:\Users\\AppData\Local\GitHub\PortableGit_\bin\git.exe
I opened File Explorer and went to the directory C:\Users\AppData\Local\
Under the view tab, I have Hidden Items checked. I cannot see a GitHub folder listed. In the search bar, I appended GitHub to the end of the directory path and got the following message
Windows can't find 'C:\Users\username\AppData\Local\GitHub'. Check the spelling and try again.
I'm trying to add Git to my environment path variable, but can't find where git is located.
In Git Bash, I was able to try which git where I got /bin/git
But I'm not sure how I can find what to put in under environment variable.
Doing a random search, I actually found that the Git folder was located here
C:\ProgramFiles(x86)\Git
But what am I supposed to enter for the path variable? This is different from the answer in the other question.
Just add the path to the command. This was the path to add to the end of the windows PATH.
C:\Program Files\Git\bin\
Now we should be able to find git.exe by typing
git
It turns out Git was being sneaky!
It was supposed to be installed in AppData/Local, but was actually installed in the Program Files(x86) directory.
I added this to my Path variable after a semicolon
C:\Windows\Program Files(x86)\Git\bin\git.exe
And magically, I can run git again.
For Windows 7 using GIT 2.7.2 I used this in the path under environment variables:
;C:\Program Files\Git\bin;C:\Program Files\Git\bin\cmd. I then typed git --version from a command prompt and got:
git version 2.7.2.windows.1
Another way is found in this place https://stackoverflow.com/a/34767523/5842689
the best thing is you can test if work in cmd.
"o verify, restart cmd and type git --version in cmd"
it works for me cause the real path in my case (Win10 x64)is
C:\Program Files (x86)\Git\bin\git.exe

Resources