Problem: pushing to Github Gist returns 403 error, as shown below:
$ git push
remote: Permission to write to gist denied.
fatal: unable to access 'https://gist.github.com/USERNAME/GISTNAME/': The requested URL returned error: 403
Solution:
- Delete existing GitHub credentials in VS Code:
- On Windows: delete any credentials related to
git
from Windows Credential Manager, as described here - On Ubuntu: delete GitHub credentials from the "Accounts" menu in VS Code, as described here and here (optionally also try pushing from a GNOME terminal instead of the built-in VS Code terminal, to determine if the issue is specific to the VS Code GitHub extension)
- On Windows: delete any credentials related to
- Generate Personal Access Token from https://github.com/settings/tokens (source), with all permissions enabled and no expiry date
- Run
git push
command again - In the authentication GUI, enter username and NOT email address (even though the GUI says "Username or email address"), and use Personal Access Token as the password (source)
On Ubuntu, the credentials might not be stored by VS Code, meaning they would have to be entered every time git push
is used. This can be avoided by setting the authentication token in the remote URL using the following instructions, where ${TOKEN_STR}
is the authentication token (optionally, git:${TOKEN_STR}
can be replaced with ${USERNAME}:${TOKEN_STR}
):
$ git remote get-url origin
https://github.com/${USERNAME}/${REPO_NAME}.git
$ git remote set-url origin https://git:${TOKEN_STR}@github.com/${USERNAME}/${REPO_NAME}.git
$ git push