Retrieve your Git username from the command line
Your Git username is stored in your local Git configuration. To see it, open your terminal and run:
git config user.name
This command returns the name you set when you first configured Git on your machine. If nothing appears, you have not yet set a username — you can add one by running git config --global user.name "Your Name" (replace "Your Name" with your actual name).
The --global flag stores your username across all repositories on your computer. Without it, the setting applies only to the current repository.
Key Takeaways
- Run git config user.name to see your current Git username in the terminal.
- Git stores usernames in configuration files, not in a password manager, so the command returns text you set yourself.
- Your Git password or authentication token is not stored in plain text and cannot be retrieved with a straightforward config command for security reasons.
- If you need to change your stored credentials, you must use your system's credential helper or regenerate an authentication token through your Git hosting service.
- Different repositories can have different usernames if you use the --local flag instead of --global.
Check your Git email address at the same time
Your email is stored alongside your username. Run:
git config user.email
This shows the email address Git uses when you make commits. Both username and email appear in your commit history, so they are visible to anyone who clones your repository or views your commits on GitHub, GitLab, or another hosting platform.
If you want to see both at once, run git config --list to display all your Git settings. This will show user.name, user.email, and many other configuration values.
Why you cannot retrieve your Git password from the terminal
Git does not store passwords in a way you can retrieve them with a command. When you push or pull from a remote repository, Git uses one of three authentication methods: HTTPS with a personal access token, SSH with a key pair, or a credential helper that stores encrypted credentials.
If you set up HTTPS authentication, Git may have cached your credentials in your system's credential manager (like macOS Keychain, Windows Credential Manager, or the Linux pass utility). To see what is cached, you would need to access that system tool directly, not Git itself.
If you set up SSH, Git uses a private key file instead of a password. You can verify the key exists by running ls ~/.ssh/id_rsa (or id_ed25519 if you use that algorithm), but you cannot view the key's contents in a way that would let you authenticate — that would defeat the purpose of using a key.
View all your Git configuration settings
To see everything Git knows about your setup, run:
git config --list
This displays your username, email, default branch name, remote URLs, and other settings. You can narrow it down by scope: git config --list --global shows only global settings, while git config --list --local shows only settings for the current repository.
Settings at the local level override global settings. So if you have set a different username for one specific project, the local setting takes precedence when you work in that folder.
Set or change your Git username in terminal
If git config user.name returns nothing, or if you want to change your username, run:
git config --global user.name "Your Name"
Replace "Your Name" with the name you want to appear in your commits. This name does not have to match your GitHub username or any other account name — it is purely what shows up in your commit history.
If you want to set a different username for just one repository, navigate into that folder and run the same command without the --global flag:
git config --local user.name "Different Name"
After you set your username, verify it worked by running git config user.name again.
Understand where Git stores your configuration
Git configuration lives in three places, in order of priority: your current repository (.git/config), your user home directory (~/.gitconfig), and your system (/etc/gitconfig). When you run git config, Git checks the local file first, then the global file, then the system file.
You can view these files directly if you want. The global file is a plain text file you can open in any editor. Run cat ~/.gitconfig to print its contents to the terminal, or open it in your text editor to make changes by hand.
Most of the time, using the git config command is safer and clearer than editing the file directly, because Git validates your input and prevents syntax errors.
Frequently Asked Questions
How do I find my GitHub username if I forgot it?
Your Git username (what you set with git config user.name) is separate from your GitHub username. To find your GitHub username, log into GitHub.com and look at the URL of your profile page, or check your account settings. Your Git username is just a label you chose — it does not have to match your GitHub account at all.
Can I have different usernames for different repositories?
Yes. Use git config --local user.name "Name" inside a specific repository folder to set a username that applies only there. That local setting overrides your global username for commits in that folder. This is useful if you want work commits under your real name and personal project commits under a pseudonym.
What if git config user.name returns nothing?
You have not set a username yet. Run git config --global user.name "Your Name" to set one. After that, git config user.name will return the name you entered. Git requires a username before you can make commits.
Is my Git password stored somewhere I can see it?
No, for security reasons. If you use HTTPS, your credentials are encrypted and stored in your system's credential manager, not in Git itself. If you use SSH, Git uses a private key file instead of a password. You cannot and should not be able to retrieve a password in plain text from the terminal.
How do I change my Git password or authentication token?
You cannot change it through Git commands. Instead, log into your GitHub, GitLab, or other hosting service account, go to your security or personal access token settings, and regenerate or update your token there. Then, the next time Git prompts you for credentials, enter the new token. Your system's credential manager will cache the new one.