-
-
Save jasonboukheir/3fdab92ece236744528447a4f7f5de00 to your computer and use it in GitHub Desktop.
git when in unix, git.exe when in wsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if pwd | grep /mnt/c > /dev/null; then | |
exec git.exe "$@" | |
else | |
exec /usr/bin/git "$@" | |
fi |
Just use it as an alias. I use fish
, I added:
alias git "git.exe"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Having this code in the Bash startup script is not going to be very useful, since you are only going to be able to use it if you are invoking git from within an interactive login shell. What you really want is to overload the
git
executable that is found in thePATH
.PATH
works exactly the same way on Linux as it does on Windows. It contains a list of directories that is searched for executables whenever you enter the name of a program in your terminal. The default path on Linux is something like/usr/local/bin:/usr/bin
. What you can see here is that/usr/local/bin
is searched before/usr/bin
, as such we can place stuff in there to overload other executables.To know where your current
git
is installed usecommand -v git
, which should give you/usr/bin/git
. Meaning, we can use/usr/local/bin
to overload it. So, let us do exactly that.That is all, no matter from where you invoke git it will be using your overloaded version going forward. Whenever you really want to us the original just use
/usr/bin/git
.You can do exactly the same with many other programs that read things from disk. For instance https://github.com/sharkdp/bat is really awesome, and available cross-platform. Just
brew install bat
on Linux andchoco install bat
on Windows and create an overload with exactly the same logic as in thegit
overload (obviously replacing the paths to the executables), and enjoy a massive speed up.