DEV Community

Cover image for Configuring Git in WSL
Stephan Lamoureux
Stephan Lamoureux

Posted on • Updated on

Configuring Git in WSL

This guide walks you through the initial Git config and setting up your Personal Access Token in a Windows dev environment.

Requirements

My two assumptions for this are that you have Windows 10/11 and WSL already installed.

The terminal commands used are based off of Ubuntu/Debian based Linux distributions.


📝 Git Config

Git should come pre-installed on most, if not all of the WSL Linux distributions. To ensure you have the latest version, use the following command in an Ubuntu or Debian based distro:



sudo apt install git


Enter fullscreen mode Exit fullscreen mode

Name

To set up your Git config file, open a WSL command line and set your name with this command (replacing "Your Name" with your preferred username):



git config --global user.name "Your Name"


Enter fullscreen mode Exit fullscreen mode

Email

Set your email with this command (replacing "youremail@domain.com" with the email you prefer):



git config --global user.email "youremail@domain.com"


Enter fullscreen mode Exit fullscreen mode

Username

And finally, add your GitHub username to link it to git (case sensitive!):



git config --global user.username "GitHub username"


Enter fullscreen mode Exit fullscreen mode

Make sure you are inputting user.username and not user.name otherwise you will overwrite your name and you will not be correctly synced to your GitHub account.

You can double-check any of your settings by typing git config --global user.name and so on. To make any changes just type the necessary command again as in the examples above.


😺 GitHub Credentials

Creating your Personal Access Token

GitHub has removed the ability to use a conventional password when working in a remote repository. You are now required to create a personal access token instead.

Personal access tokens (PATs) are an alternative to using passwords for authentication to GitHub when using the GitHub API or the command line.

Follow these docs for step-by-step instructions on creating your personal token.

Git Credential Manager

Once you enter in your token the first time, it can be stored via Git Credential Manager (GCM) so you won't have to authenticate yourself each time.

You can have Git installed in WSL and also in Windows at the same time. Git for Windows includes GCM and is the preferred way to install it.

Windows Git Installer Menu

You can also download the latest installer for Windows to install the GCM standalone version.

Storing Your Token

Once Git Credential Manager is installed you can set it up for use with WSL. Open your WSL terminal and enter this command:



git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager-core.exe"


Enter fullscreen mode Exit fullscreen mode

Note:

If you ever receive the following error message:



/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe store: 1: 
/mnt/c/Program Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe: not found


Enter fullscreen mode Exit fullscreen mode

Try using the this command:



git config --global credential.helper store


Enter fullscreen mode Exit fullscreen mode

🔚 Conclusion

That wraps up the basics for a Git config on Windows! If you are interested in learning more, check out my Git a Grip series.

References

Top comments (0)