Using GH_CONFIG_DIR for different authentications doesn't work as expected #188559
Replies: 4 comments 2 replies
-
|
sigh and this is exactly my annoyance with having multiple logins/identities, created under the wrong login since my current browser session is using the other login and forgot to switch before hitting create. |
Beta Was this translation helpful? Give feedback.
-
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
|
I ran into this exact issue. The problem is that gh auth status reads your config directory directly, but git push relies on Git credential helper chain. If Git is configured to use a system credential manager, it will bypass gh entirely and ignore GH_CONFIG_DIR. Run git config --get credential.helper in the repo. If you see osxkeychain, manager-core, or cache, you need to point Git directly at the CLI. Run git config --local credential.helper "!gh auth git-credential". Make sure GH_CONFIG_DIR is exported in the exact shell session where you run git push. I am not 100% sure if your gist covers this, but terminal multiplexers and IDEs sometimes strip environment variables before spawning git processes. What does git config --get credential.helper return in the repo you are pushing from? |
Beta Was this translation helpful? Give feedback.
-
|
The root cause here is that So the fix is two parts:
git config --local credential.helper "!gh auth git-credential"The One gotcha: if you have git config --show-origin --get-all credential.helperThat'll show you every credential helper that's configured and where it comes from. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussion Type
Bug
Discussion Content
So I have separate work & personal Github credentials, as I'm sure many do. So I've been trying to automatically switch between credentials without needing to remember to do
gh switchor anything like that. So I've come up with a guide to do that using theGH_CONFIG_DIRenvironment parameter.It looks like it works fine, using
gh auth statusit's showing the correct account authentication, but when I try and do agit push, it shows the other account authentication that I last did withgh auth login.I can't help but think this is a bug, since the environment
GH_CONFIG_DIRis correct, andgh auth statusis showing me exactly what I expect.Here's the guide that I came up with. Unless my understanding of how
GH_CONFIG_DIRis supposed to function is faulty.https://gist.github.com/Drizzt321/47cf383a19535940a26616d982783d2e
Beta Was this translation helpful? Give feedback.
All reactions