Skip to content

Instantly share code, notes, and snippets.

@hackjutsu
Last active November 30, 2025 19:22
Show Gist options
  • Select an option

  • Save hackjutsu/7564718dda716e0de7d6770a5f570d75 to your computer and use it in GitHub Desktop.

Select an option

Save hackjutsu/7564718dda716e0de7d6770a5f570d75 to your computer and use it in GitHub Desktop.
[GitHub Authentication] How to authenticate Git to push changes to #GiHub with #gh

As I kept running into GitHub auth issues on each new local setups, I documented the steps here.

This gist documents how to set up your local dev env, especially on a headless Ubuntu machine, to push local Git changes to remote GitHub repositories.

It features

  • fine-grained auth token
  • headless env, e.g. remote ubuntu dev machine, where browser-based auth does not work well

Generate a personal access token in GitHub UI

To acquire the permission to push local changes to the remoate GitHub repos.

  • Create a personal access token in your GitHub website.
    • [Your profile icon] --> [Personal access tokens] --> [Fine-grained tokens] --> [Generate new token]
    • Fill out "Token name" and "Expiration".
    • Select All repositories for "Repository access".
    • In the "Permissions" section, click on "+ Add permissions" button
      • Select Contents with Read and write access. This should give you permissions to push changes to GitHub.
    • Click "Generate token" and store the token in a safe place(e.g. 1Password).

Authenticate local Git to push changes to GitHub

  • Install gh-cli locally.
  • Login gh with the previous personal access token
gh auth login

## Here is an example of my personal setup
#  Where do you use GitHub?  --> GitHub
#  What is your preferred protocol for Git operations on this host? --> HTTPS
#  How would you like to authenticate GitHub CLI? --> Paste an authentication token (the personal access token)
  • Make Git use GitHub CLI’s credential helper.
gh auth setup-git

# Now you should be able to push changes
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment