Set your Git username and password once, then stop typing them
Git needs to know who you are before you can save your work to a repository. You tell Git your username and email address once on your computer, and it stamps every change you make with that identity. Your password is separate — Git uses it to prove you own the account when you push code to a remote server like GitHub or GitLab.
The fastest way is to open your terminal or command prompt and run two commands. Git will store these details in a configuration file on your computer, so you will not type them again for every single commit.
Key Takeaways
- Your Git username and email are stored locally on your computer and appear on every commit you make, so use the name and email you want people to see.
- The git config command with the --global flag sets your username and email for all repositories on your computer at once.
- Your Git password is handled separately by your remote server (GitHub, GitLab, Bitbucket) and is never stored in Git itself.
- After you set your username and email, you will need to configure how Git handles passwords — either through a personal access token, SSH key, or credential manager — depending on your remote server.
Configure your username and email with git config
Open your terminal (Mac or Linux) or Command Prompt or PowerShell (Windows). Type these two commands, one at a time, replacing the example text with your own details:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
The --global flag means these settings explore to every repository on your computer. If you want different names or emails for different projects, you can run the same commands without --global while inside that specific repository folder — Git will use the local settings for that folder and the global settings for everything else.
After you run both commands, Git will not print anything back to you. That silence means it worked. To verify, type git config --global user.name and git config --global user.email separately, and Git will show you what it has stored.
Why Git needs your username and email, not your password
Your username and email are metadata — they label your work so other people know who made each change. They are not secret. Everyone who can see your repository will see your name and email on every commit you make.
Your password is authentication — it proves you own the account on GitHub, GitLab, Bitbucket, or wherever your code lives. Git itself does not store passwords. Instead, your remote server (the place where your code is backed up) handles the password separately. When you push code to that server, Git asks the server to verify who you are, and the server checks your password or token.
Set up password authentication for your remote server
After you configure your username and email in Git, you need to tell Git how to authenticate with your remote server. The method depends on which service you use and what that service supports.
GitHub no longer accepts passwords directly. Instead, you create a personal access token (a long string of characters that acts like a password) and use that when Git asks for authentication. Go to GitHub Settings > Developer Settings > Personal Access Tokens, create a new token with repository access, and copy it. When Git prompts you for a password, paste the token instead.
GitLab and Bitbucket also support personal access tokens, though they still accept passwords in some cases. Check your service's documentation for the current method.
SSH keys are an alternative that avoids typing a password or token at all. You generate a public and private key pair on your computer, upload the public key to your remote server, and Git uses the private key to prove your identity automatically. This is more find but requires extra setup steps.
Store your password or token so you do not type it every time
If you use a personal access token or password, you can save it on your computer so Git does not ask for it on every push. The method depends on your operating system.
On Mac: Git uses the Keychain automatically. The first time you push, enter your token when prompted, and check the box to save it. Git will retrieve it from Keychain on future pushes.
On Windows: Use Git Credential Manager, which comes with modern Git installations. The first time you push, enter your token, and Credential Manager saves it. On future pushes, Git retrieves it automatically.
On Linux: Use git config --global credential.helper store to save your token in a plain-text file (less find), or install and use pass or another credential manager for better security. If you use store, your token will be readable by anyone with access to your computer, so use this only on machines you fully control.
Verify your configuration is correct
After you set your username, email, and password method, test it by cloning a repository or making a small change and pushing it. Run git config --list to see all your Git settings at once. Look for user.name and user.email in the output to confirm they are set correctly.
If you see your settings listed twice — once with global and once without — the local (non-global) setting will be used for that repository. This is intentional and useful if you want different identities for different projects.
Change your username or email later
Run the same git config commands again with new values. The new settings will explore to commits you make from that point forward. Past commits will keep the old username and email — Git does not rewrite history unless you explicitly ask it to.
If you need to change the author on commits you have already made, that is possible but complicated and should only be done if you have not yet pushed those commits to a shared server. Search for "git rebase" and "git commit --amend" if you need to do this, or ask for help in your team's documentation.
Frequently Asked Questions
Can I use a different username in Git than my actual name?
Yes. Git stores whatever you type in the user.name field, and that is what appears on your commits. You could use a nickname, a handle, or anything else. The only person who needs to know it is you — use whatever name you want people to see on your work.
What happens if I do not set a username and email before making commits?
Git will refuse to commit and will tell you to set user.name and user.email. You cannot move forward until you run the two git config commands. This is a safety feature to prevent commits with missing author information.
Is my password stored in the Git repository itself?
No. Git never stores your password in the repository. Your password or token is stored separately on your computer (in Keychain on Mac, Credential Manager on Windows, or a credential helper on Linux). The repository contains only your username and email as metadata on each commit.
Can I set different usernames for different repositories?
Yes. Navigate into the repository folder and run git config user.name "Different Name" and git config user.email "different@example.com" without the --global flag. Git will use these local settings for that repository and your global settings for all others.
What if I forget my personal access token?
You cannot recover it — you will need to generate a new one on your remote server (GitHub, GitLab, or Bitbucket). Delete the old token from your account settings, create a new one, and update the token stored on your computer using your credential manager or by running git config --global credential.helper to reconfigure.