Git Credentials on MacOS — How to Cache, Update, and Delete Your GitHub Account Credentials
This article is for MacOS users.
In this article, I will walk you through on how to
- Save your GitHub account credentials on your computer.
- Update the Git credentials after you change your Github username and/or PW.
- Delete the Git credentials from your computer.
UPDATE (since August, 2021)
Github stopped supporting authentication by HTTPS, so you need to use SSH or some other token-based method instead.
You can refer my newer article on how to set up SSH to use with your Github account for git operations from your local machine:
Git credentials
When you clone GitHub repositories using HTTPS, you will need to authenticate your credentials. Git will prompt you to enter your GitHub username and password.
This authentication process must pass before the cloning of a remote repository to your local environment can be successfully completed.
But you don’t want to do this every time you clone a Github repository, so let’s find out how to make Git remember your credentials on your computer.
Caching your GitHub credentials in Git
You can tell Git to remember your credentials by using a credential helper, so that you don’t have to enter your username and password every time you clone a GitHub repository.
On Mac, you can use osxkeychain helper
.
Use the following command on your terminal:
git config --global credential.helper osxkeychain
This tells Git to use the osxkeychain
credentials helper
.
Once you have authenticated successfully, your credentials will be stored in the MacOS keychain and will be used every time you clone your GitHub repository.
From this point on, you won’t have to re-enter your credentials unless you change your credentials (username, password) on GitHub.
Updating your GitHub credentials in Git
If you change your username and/or password for your GitHub account, you will have to update your Git credentials stored in your local computer.
There are two ways you can update your Git credentials:
- Update through MacOS’s
Keychain Access
application. - Delete current credentials and then save the new credentials (through command line).
Update credentials via MacOS Keychain Access
If you have set credentials.helper osxkeychain
on your Mac, you can update your credentials using MacOS's Keychain Access
app.
To update existing GitHub keychain,
- Open
Keychain Access
on your mac (you can use spotlight) - Search for
github.com
- Select the
github.com
keychain item - Edit or delete your GitHub account credentials.
Delete credentials via command line
You can use command line to delete existing credentials and then re-enter your new username and/or password when prompted.
To delete existing credentials, enter the following command:
git credential-osxkeychain erase
host=github.com
protocol=https
> [Press Return]
If successful, nothing will print out.
Now when you try to clone a GitHub repository, you will be prompted to enter your credentials. Here you can enter your new credentials.
To tell Git to remember the new credentials, you can use
git config --global credentials.helper osxkeychain
command again.