Git - Troubleshooting

Last Updated: 2023-01-15

How to fix "detached HEAD"?

Option 1: discard changes and go back. These 2 are equivalent.

$ git switch <branch-name>
$ git checkout <branch-name>

Option 2: create a new branch at the current HEAD.

$ git checkout -b <new-branch-name>

macOS Uses Wrong Git Account

If multiple GitHub accounts are logged in using Mac OS X, the account info might be stroed by Keychain Access. Maven release plugin may fails for using wrong Github account.

[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] remote: Permission to <...>/<...>.git denied to <...>.
[ERROR] fatal: unable to access 'https://github.com/<...>/<...>.git/': The requested URL returned error: 403

Solution: find Keychain Access in spotlight or by

Applications->Utilities->Keychain Access.app

Search for github and remove the records.