Skip to content

Add command/flag to set user.name and user.email in global config #6096

Open

Description

@michaelweinold

Describe the feature or problem you’d like to solve

gh auth setup-git currently only sets ~/.gitconfig to

[credential "https://github.com"]
        helper =
        helper = !/usr/bin/gh auth git-credential
[credential "https://gist.github.com"]
        helper =
        helper = !/usr/bin/gh auth git-credential

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

Activity

  1. added
    enhancement
    on Aug 18, 2022
  2. added
    needs-triage
    on Aug 18, 2022
  3. added
    discuss
    and removed
    needs-triage
    on Aug 24, 2022
  4. vilmibm commented on Aug 24, 2022

    @vilmibm
    Contributor

    It would be nice for gh to help with this; we'll discuss in our next planning meeting if the correct place to do it is in setup-git or not.

  5. added
    help wanted
    and removed
    discuss
    on Sep 21, 2022
  6. mislav commented on Sep 21, 2022

    @mislav
    Contributor

    I'd love if this was part of gh auth setup-git or even gh auth login when the user chooses to authenticate git with their GitHub CLI info.

    Here is where we get the authenticated user after gh auth login is complete:

    userLogin, err := getViewer(oauthHost, token.Token, IO.ErrOut)

    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!

  7. samuel-adekunle commented on Dec 17, 2022

    @samuel-adekunle

    Hey, is help still wanted on this? I opened a PR a while ago and haven't gotten any response.

  8. michaelweinold commented on Jan 9, 2023

    @michaelweinold
    Author

    @mislav is this still on the radar? @samuel-adekunle kindly opened #6643 to address this.

  9. samuel-adekunle commented on Jan 9, 2023

    @samuel-adekunle

    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.

  10. soleust commented on Oct 1, 2023

    @soleust

    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

  11. added
    gh-auth
    on Oct 2, 2023
  12. added
    core
    and removed
    help wanted
    on Oct 18, 2023
  13. aidenfarley commented on Aug 12, 2024

    @aidenfarley

    Is there anything that needs a contribution in order for this to be a feature?

  14. soleust commented on Aug 16, 2024

    @soleust

    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

  15. 34j commented on Oct 5, 2024

    @34j

    Temporary workaround:

    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 ".[1].email")
    echo "Setting $user <$email> as the default Git user..."
    git config --global user.name "$user"
    git config --global user.email "$email" 
  16. notPlancha commented on Oct 9, 2024

    @notPlancha

    Temporary workaround:

    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 ".[1].email")
    echo "Setting $user <$email> as the default Git user..."
    git config --global user.name "$user"
    git config --global user.email "$email" 

    Here´s for powershell

    $user = (gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user | ConvertFrom-Json).login
    $email = ((gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user/emails | ConvertFrom-Json)[1].email)
    Write-Host "Setting $user <$email> as the default Git user..."
    git config --global user.name $user
    git config --global user.email $email 
  17. borland502 commented on Nov 25, 2024

    @borland502

    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/6096
    if [[ $(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
  18. dogbane-dev commented on Apr 14, 2025

    @dogbane-dev

    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

  19. falo2k commented on Sep 6, 2025

    @falo2k

    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.

  20. pit-hub commented on Sep 30, 2025

    @pit-hub

    Temporary workaround:

    @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:

    GH_USER_INFO=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user)
    GH_USER_ID=$(echo "${GH_USER_INFO}" | jq -r .id)
    GH_USER=$(echo "${GH_USER_INFO}" | jq -r .login)
    GH_PRIVATE_EMAIL="${GH_USER_ID}+${GH_USER}@users.noreply.github.com"
    echo "Git User:  $GH_USER, User Email: $GH_PRIVATE_EMAIL"
    
    git config --global user.name "$GH_USER"
    git config --global user.email "$GH_PRIVATE_EMAIL"
    

    NOTE:
    Haven't tested but the "/user" API also provides a "email" field, which is 'null', it may be of the privacy settings activated.

  21. BrianHung commented on Nov 18, 2025

    @BrianHung

    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).

  22. vkukshiev commented on Dec 22, 2025

    @vkukshiev

    I might do this feature if you applied this idea.

  23. added
    pitch
    on Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreenhancementgh-authpitch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions