Git aliases are a fantastic way to perform repetitive commands with less keystrokes. In this tutorial you'll learn how to easily share these aliases made on Windows with your WSL instance and vice-versa!
✔️ Pre-reqs
- git installed on:
- Windows (git-bash is fine)
- WSL
- Some helpful git aliases
- Five or so minutes
📃 Setup
Create the shared git aliases file
Under Windows using cmd.exe
:
# Using %USERPROFILE%/config/shared-git-aliases
cd %USERPROFILE%
mkdir config
notepad.exe %USERPROFILE%\config\shared-git-aliases
Inside of the shared-git-aliases file, add a single line [alias]
and below add aliases accordingly:
[alias]
s = status
sw = switch
Configure Windows and WSL to use the shared aliases file
Copy the full path of your shared-git-aliases file and open git config using cmd.exe
:
git config --global --edit
NOTE: any aliases defined here will only exist on Windows. You must move the aliases to the included file to enable access in WSL.
Add the following, replacing the path with your shared-git-aliases file. We can avoid escaping the path by using forward slashes:
[include]
path = C:/Users/YOUR-USER/config/shared-git-aliases
Copy the path here and open a WSL terminal. Convert the Windows path to be accessible via WSL:
wslpath -u "C:/Users/YOUR_USER/config/shared-git-aliases"
Almost there! Now edit gitconfig on WSL:
git config --global --edit
Add the following:
[include]
path = /mnt/c/Users/YOUR_USER/config/shared-git-aliases
Save the file, and voila! Your aliases should be working.
Top comments (0)