Vincent
Vincent

Reputation: 8796

How to add git to PATH (Bash on Windows)

I am using Bash on Ubuntu on Windows, and I installed git. How do I add git to my PATH?

Upvotes: 5

Views: 22742

Answers (2)

Satyen Achint
Satyen Achint

Reputation: 31

The solution assumes u want to access git inside WSL in your Windows Environment

Check this Out https://github.com/ardevd/gitwrap/releases

This wrapper pipes output from WSL to windows and also works on android studio claimed by the developer

This Wrapper was not developed by me for any issues plz post on the github page

Upvotes: 2

VonC
VonC

Reputation: 1323115

The General command is (using setx):

setx PATH=%PATH%;C:\path\to\Git\bin

On WSL (Windows Subsytem for Linux), you would type, after installation:

which git

It should be already in your PATH (/usr/bin or /usr/local/bin)

If it is not, you can try and find it: find / -name "git", and add it to your ~/.profile with:

export PATH=$PATH:/path/to/git

But be aware the WSL will install an old version of Git.

Fir the most recent one, use:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git-core

Where is /usr/local/bin on Windows?

As mentioned in BashOnWindows issue 402:

Under C:\Users\**user**\AppData\Local\lxss, You will find:

  • root folder
  • home folder
  • and a hidden rootfs folder (\bin, \boot, \dev, \etc...)

DON'T CHANGE ANYTHINK INSIDE! SERIOUSLY! 🚨

Access Windows files via /mnt/**letter**/

And:

Maybe I don't fully understand what Bash on Ubuntu on Windows is.

See Wikipedia WSL entry:

Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10.
Windows Subsystem for Linux is only available on 64-bit editions of Windows 105 and can be activated on Windows 10 Anniversary Update and later.
WSL uses fewer resources than a full virtualized machine, the most direct way to run Linux software on a Windows computer, while also allowing users to use Windows apps and Linux tools on the same set of files.5

The OP adds:

So if I install git and it's in /usr/bin/git, does that correspond to a particular folder such as C:\Program Files\etc...?

Yes, under C:\Users\**user**\AppData\Local\lxss\rootfs\usr\..., but you are not supposed to access it directly. You only use it through the WSL bash.

Is setting my PATH different by putting it in my ~/.profile vs. going into Control Panel --> System Properties --> Environment Variables

Yes, completely. If you want to set your Windows Environment Variables PATH, you need to use Git for Windows, as described in here.

Upvotes: 8

Related Questions