{
  "id": 3453678,
  "title": "Using Multiple GitHub Accounts: Automatically Select the Correct `gh` PAT Based on Repo Owner",
  "url": "https://urgent.news/2026/08/26/using-multiple-github-accounts-automatically-select-the-correct-gh",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-26T07:16:37.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/vast-cow/using-multiple-github-accounts-automatically-select-the-correct-gh-pat-based-on-repo-owner-4l3g"
  },
  "original_language": "en",
  "account": "Managing multiple GitHub accounts can be challenging, especially when it comes to selecting the correct Personal Access Token (PAT) for different repositories. When working with repositories from various owners, such as GitHub and another-user, Git Credential Manager or gh auth git-credential may default to the currently active account, resulting in errors like \"Permission denied.\" To overcome this issue, GitHub CLI (gh) provides a solution that automatically selects the appropriate PAT based on the repository owner.\n\nThe core of this solution lies in modifying the .gitconfig file to include the `useHttpPath = true` setting. This allows the credential helper to receive the full repository URL, including the owner portion. Inside the helper, the first element of the path is extracted and used to retrieve the corresponding PAT with the command `gh auth token --user ACCOUNT`.\n\nWhen accessing a repository like `https://github.com/aont/foo.git`, the command `gh auth token --user aont` is executed automatically, retrieving the correct PAT for that account. Similarly, for `https://github.com/another-user/bar.git`, the command `gh auth token --user another-user` is invoked. This process eliminates the need to manually switch accounts or use external scripts.\n\nIt's important to note that the `helper =` line should be added to the .gitconfig file, resetting any previously configured credential helpers. This ensures that only this specific helper is used when dealing with multiple GitHub accounts.\n\nThe same approach can be applied to Git repositories, allowing for seamless credential management across different repositories and services. By configuring the credential helper based on the remote URL, you can treat GitHub repositories and Gists with the same rules, making the process more efficient and streamlined.",
  "summary": "When using multiple GitHub accounts, the process of selecting the correct Personal Access Token (PAT) for git push or git pull over HTTPS can be a bit cumbersome. Specifically, when dealing with repositories from multiple owners, such as: https://github.com/aont/foo.git https://github.com/another-user/bar.git Git Credential Manager or gh auth git-credential might default to the currently active…",
  "key_points": [
    "Modify .gitconfig with useHttpPath = true for full repo URLs.",
    "Extract repository owner from URL to retrieve corresponding PAT.",
    "Eliminate manual account switching with automatic PAT selection."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}