How to add Conda to Git Bash (Windows)

Felipe A. Moreno
3 min readMar 8, 2021

--

For windows users, is not common to use the bash command in the command prompt. Also, in Git bash (the git console with some Linux commands) in Windows. For a Linux user, change to windows could be a bit annoying when we try to make some changes in the system via commands instead of the GUI application.

One example is the fastly way to use python/conda/git in the same console. In this case Git Bash. But when you install Anaconda in Windows, you should open a dedicated command prompt to use Anaconda. In addition, a dedicated console called Git Bash controls your repositories.
For that, today I gonna show you how to add the conda command into the Git Bash to get it all in one python-conda-git bash.

Conda doesn't work inside of git bash

Installing Conda

This step is easy, you can found how to install it on windows pressing here.

Once you have installed Conda, go to the folder: Anaconda/etc/profile.d/

Open git bash

This will open a new instance of Git Bash to the correct directory.

Now, so long as the path to your file has no spaces, you can add conda.sh to your .bashrc with this simple command:

echo ". ${PWD}/conda.sh" >> ~/.bashrc

If the path does contain spaces (such as in your username), you will need to add single quotes in the command like so:

echo ". '${PWD}'/conda.sh" >> ~/.bashrc

After running this command, you will need to close Git Bash and reopen it for it to take effect.

Then, reopen Git bash and tap conda

Conda on git bash

Troubles with python

If you already installed conda in your system (but no python), when you try to start python into git bash, you'll see a message like this:

Cant recognize python in WindowsApps

To solve this, we will use the python installed within Conda environment, similar to above, we need to add this line into the file .bashrc :

alias python=’winpty /C/Users/Adrian/anaconda3/python.exe’
Ou .bashrc should be like this

Finally, we can open Python into Git bash:

Python on git bash

I hope you enjoyed this post :D :D

--

--

Felipe A. Moreno
Felipe A. Moreno

Written by Felipe A. Moreno

Computer Scientist at(@UNIoficial) and Cat lover ❤. Visit http://www.fmorenovr.com/

Responses (1)