Are you setting up a new Linux machine and need to set up Git? This is by far the fastest and easiest way to set up your Git credentials, assuming you’re using GitHub and not another version control service.
TL;DR
Do the following:
- Get GitHub CLI tools. Follow instructions here: https://github.com/cli/cli/blob/trunk/docs/install_linux.md
- Authenticate: run
gh auth login
and follow the prompts to log into GitHub - Use
gh
as the Git credential helper: rungh auth setup-git
- Set up the username and email associated with your commits:
git config --global user.name "first.last" git config --global user.email "<first.last@email.com>"
Done! Try cloning a repository to make sure everything worked with
git clone ...
Motivation
The first time you log into GitHub on Windows PowerShell, a browser pops up and you’re instructed to log into GitHub via the web UI. The Windows Git Credential Manager then saves your credentials behind the scenes, and you never have to worry about entering your password again.
Similarly, WSL utilizes Windows’ Git Credential Manager to handle storing your credentials.
On Linux, it is not so easy. Both Git and the official GitHub docs point to the Git Credential Manager, and after installing it, you need to take additional non-trivial steps to finish setting it up. All credential store options available to Linux distributions (in git config --global credential.credentialStore <store_option>
) involve additional third-party tools. Why isn’t there a simple UI pop-up like Windows? This is where the GitHub CLI tool comes to the rescue.
In addition to managing your credentials, the GitHub CLI tool lets you interact with GitHub itself in the command line, such as opening PRs, issues, interacting with projects, and so much more!