You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add command/flag to set user.name and user.email in global config #6096
coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-authrelating to the gh auth commandpitchpitched internally for prioritisation
so trying to add commits in any repository throws the usual
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
Proposed solution
A gh command to set username and email (either public email address or the users.noreply.github.com if privacy is enabled) from github.com account. Perhaps implemented as a flag of the gh auth setup-git command.
Additional context
N/A
Reacted by Jason Morganson, Samuel Adekunle, Heyang Qin, soleust, Hyunbin Seo, jhmaster, Anthony Tiger Ilareguy, ViRGiL175, Ian MacLeod, Ethan Shumate and 49 more
Currently we only fetch their login handle, but we could fetch their email and name fields. Then, the resulting information could be written to their .gitconfig, but only if this information isn't configured already. PRs welcome!
Thought this was the behavior of gh auth setup-git, but I guess not :c hope this gets added.
The email settings page where you actually find the git-provided email it's a little hard to find the email that you're given. It's annoying having to copy it from the middle of a sentence. The whole reason I downloaded the cli was to set this up for me easily
Reacted by Alex vG, wei, Chris Mar, Jonas Sander, alextitov1, Wanjohi, Michael Payne, Prasook Jain, MP3Martin, Aiden Farley and 5 more
Whenever I teach someone how to use git and GitHub, setting up their noreply address is always the most annoying part, because I have to get them to find the email hidden in a small little piece of text in the email settings page. The gh cli being able to do this for us would make so many peoples lives easier. Or frankly there should just be a giant textbox in the email settings page for "COPY GIT EMAIL"
Kind of disappointing a perfectly reasonable #6643 got closed
Reacted by Ben Ayles, Aiden Farley, Dan-George Filimon, Tanner and sleeptightAnsiC
There is a slight problem with the dominant workaround in that corporate/org accounts will not work with it. You'll be prompted to refresh with user scope.
# Github CLI temporary workaround# https://github.com/cli/cli/issues/6096if [[ $(command -v gh) ]];then# The workaround needs user scope and at least for corporate accounts, that isn't the default
gh auth refresh -h github.com -s user
user=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user | jq -r .login)
email=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user/emails | jq -r ".[0].email")echo"Setting $user <$email> as the default Git user..."
git config --global user.name "$user"
git config --global user.email "$email"fi
Reacted by w1nsid, Anton, srutkowski-nirvana and Chase Holdren
Sorry to drag this back up but any hope of this being revisited? Would love to be able to have the git commit config switch over when switching between auth profiles
Reacted by Felipe, Magnetite, vmateuszku, Ayomikun Akinrinade, jiawei94, Nitin Krishna Mucheli, Maxime Zaremba, fa-az and sleeptightAnsiC
Setting up a new environment and ran across this exact need. Would love to see some movement on it. Going hunting through settings pages to grab my noreply address isn't really an ideal approach.
Reacted by sleeptightAnsiC, Manuel Porto, Daniel Niccoli and Brian Hubbell
As I'm using private email and accessing user email requires user scope which makes it complicated. When I examined the '/user' output it is simpler for private emails juste do it from the '/user' api response. So for me the workaround is:
This is useful if we have a github user oauth token and want to submit PRs for them using git.. not gh (models / LLMs are trained better to use git rather than gh cli).
coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-authrelating to the gh auth commandpitchpitched internally for prioritisation
Activity
vilmibm commentedon Aug 24, 2022
It would be nice for
ghto help with this; we'll discuss in our next planning meeting if the correct place to do it is insetup-gitor not.mislav commentedon Sep 21, 2022
I'd love if this was part of
gh auth setup-gitor evengh auth loginwhen the user chooses to authenticate git with their GitHub CLI info.Here is where we get the authenticated user after
gh auth loginis complete:cli/internal/authflow/flow.go
Line 132 in b82884a
Currently we only fetch their
loginhandle, but we could fetch theiremailandnamefields. Then, the resulting information could be written to their.gitconfig, but only if this information isn't configured already. PRs welcome!samuel-adekunle commentedon Dec 17, 2022
Hey, is help still wanted on this? I opened a PR a while ago and haven't gotten any response.
michaelweinold commentedon Jan 9, 2023
@mislav is this still on the radar? @samuel-adekunle kindly opened #6643 to address this.
samuel-adekunle commentedon Jan 9, 2023
Yes @michaelweinold , I'm currently working on adding this feature to the setup-git command rather than as a flag which is what I did in #6643.
soleust commentedon Oct 1, 2023
Thought this was the behavior of
gh auth setup-git, but I guess not :c hope this gets added.The email settings page where you actually find the git-provided email it's a little hard to find the email that you're given. It's annoying having to copy it from the middle of a sentence. The whole reason I downloaded the cli was to set this up for me easily
aidenfarley commentedon Aug 12, 2024
Is there anything that needs a contribution in order for this to be a feature?
soleust commentedon Aug 16, 2024
Whenever I teach someone how to use git and GitHub, setting up their noreply address is always the most annoying part, because I have to get them to find the email hidden in a small little piece of text in the email settings page. The gh cli being able to do this for us would make so many peoples lives easier. Or frankly there should just be a giant textbox in the email settings page for "COPY GIT EMAIL"
Kind of disappointing a perfectly reasonable #6643 got closed
34j commentedon Oct 5, 2024
Temporary workaround:
notPlancha commentedon Oct 9, 2024
Here´s for powershell
borland502 commentedon Nov 25, 2024
There is a slight problem with the dominant workaround in that corporate/org accounts will not work with it. You'll be prompted to refresh with user scope.
dogbane-dev commentedon Apr 14, 2025
Sorry to drag this back up but any hope of this being revisited? Would love to be able to have the git commit config switch over when switching between auth profiles
falo2k commentedon Sep 6, 2025
Setting up a new environment and ran across this exact need. Would love to see some movement on it. Going hunting through settings pages to grab my noreply address isn't really an ideal approach.
pit-hub commentedon Sep 30, 2025
@borland502
As I'm using private email and accessing user email requires user scope which makes it complicated. When I examined the '/user' output it is simpler for private emails juste do it from the '/user' api response. So for me the workaround is:
NOTE:
Haven't tested but the "/user" API also provides a "email" field, which is 'null', it may be of the privacy settings activated.
BrianHung commentedon Nov 18, 2025
This is useful if we have a github user oauth token and want to submit PRs for them using git.. not gh (models / LLMs are trained better to use git rather than gh cli).
vkukshiev commentedon Dec 22, 2025
I might do this feature if you applied this idea.