Troubleshooting of GIT: Difference between revisions

Jump to navigation Jump to search
Line 379: Line 379:


so Git always uses the correct SSH key.
so Git always uses the correct SSH key.
=== Git Push Failed: Invalid username or token (GitHub No Longer Supports Password Authentication) ===
'''Problem'''
Running <code>git push</code> produces the following error:
<pre>
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/team_name/repo_name/'
In a case you entered incorrect password, please
update it in Keychain Access application.
</pre>
'''Diagnosis'''
First check the current login status of the GitHub CLI:
<pre>
gh auth status
</pre>
If the token has expired, a message similar to the following will appear:
<pre>
github.com
  X Failed to log in to github.com account UserName (keyring)
* Active account: true
* The token in keyring is invalid.
* To re-authenticate, run: gh auth login -h github.com
* To forget about this account, run: gh auth logout -h github.com -u UserName
</pre>
You can also directly query the GitHub credentials stored in the macOS Keychain:
<pre>
security find-internet-password -s github.com
</pre>
'''Cause'''
This error is typically caused by one of the following:
* An old GitHub account password (rather than a token) is stored in the macOS Keychain, and Git's attempt to authenticate with that password fails.
* The Personal Access Token in the <code>gh</code> keyring has expired, been revoked, or had its permissions changed.
* A token or SSH key was never set up, so Git is still falling back to the legacy password authentication flow.
'''Solution'''
'''Re-authenticate the GitHub CLI'''
<pre>
gh auth login -h github.com
</pre>
Select the following options in order:
* What is your preferred protocol for Git operations on this host? → <code>HTTPS</code> (matches the existing remote protocol)
* How would you like to authenticate GitHub CLI? → <code>Login with a web browser</code>
A one-time code will be displayed. Copy it and press Enter; a browser window will open the GitHub device authorization page to complete the login:
<pre>
! First copy your one-time code: XXXX-XXXX
Press Enter to open https://github.com/login/device in your browser...
✓ Authentication complete.
* gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as UserName
</pre>


=== Git Shows Files as Modified After chmod — File Mode Changes ===
=== Git Shows Files as Modified After chmod — File Mode Changes ===

Navigation menu