This post is targeted for macOS users
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 authentification process must pass before the cloning between local and remote repositories can be successfully completed.
Caching your GitHub credentials in Git
- You can tell Git to remember your credentials so that you don't have to enter your username and pw every time you clone a git repository by using a credential helper
- On Mac, you can use
osxkeychain helper
- Use the following command:
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 everytime you clone your GitHub repository
- you won't have to re-enter your credentials unless you change your credentials (username, password) on GitHub
Updating your GitHub credentials in Git from macOS keychain
- If you have changed your GitHub username and/or password for your GitHub account, you will have to update your credentials stored in your local computer
- If you have set
credentials.helper osxkeychain
on your Mac, you can update using macOS's Keychain Access
app
Updating via Keychain Access
- To update existing GitHub keychain, open
Keychain Access
on your mac (you can use spotlight to search for and open), search for and select github.com
- After selecting the
github.com
keychain item, you can update your GitHub username
Deleting credentials via command line
- You can use command line command to delete exising credentials and 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 the
git config --global credentials.helper osxkeychain
command again
Reference:
docs.github.com - Caching your GitHub credentials in Git
docs.github.com - Updating credentials from the macOS Keychain