DEV Community

Cover image for Sharing Git Aliases between Windows & WSL
Cody Antonio Gagnon
Cody Antonio Gagnon

Posted on • Updated on

Sharing Git Aliases between Windows & WSL

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!

git comic

Source: https://xkcd.com/1597/

✔️ 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
Enter fullscreen mode Exit fullscreen mode

Inside of the shared-git-aliases file, add a single line [alias] and below add aliases accordingly:

[alias]
s = status
sw = switch
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Almost there! Now edit gitconfig on WSL:

git config --global --edit
Enter fullscreen mode Exit fullscreen mode

Add the following:

[include]
      path = /mnt/c/Users/YOUR_USER/config/shared-git-aliases
Enter fullscreen mode Exit fullscreen mode

Save the file, and voila! Your aliases should be working.

git status alias

Top comments (0)