Skip to content

Instantly share code, notes, and snippets.

@jakelevi1996
Last active June 22, 2024 17:08
Show Gist options
  • Save jakelevi1996/9901b95b45aa9d0f4e888fa7ae111120 to your computer and use it in GitHub Desktop.
Save jakelevi1996/9901b95b45aa9d0f4e888fa7ae111120 to your computer and use it in GitHub Desktop.
Fix Gists not pushing

Fix Gists not pushing

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:

  1. 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)
  2. Generate Personal Access Token from https://github.com/settings/tokens (source), with all permissions enabled and no expiry date
  3. Run git push command again
  4. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment