How to configure your Git username and password
Git needs to know who you are before you can save your work. You tell Git your name and email address through two configuration commands — one for your username and one for your email. These details appear on every commit you make, so your collaborators know who wrote each change. The password part works differently: Git uses either a personal access token (a long string of characters) or SSH keys (a pair of linked security files) instead of your actual account password.
The fastest path is to set your username and email globally on your computer, then use a personal access token when Git asks for a password. This takes about five minutes and works whether you use Windows, Mac, or Linux.
Key Takeaways
- Your Git username and email are set separately from your GitHub or GitLab account password using two command-line commands.
- Use git config --global user.name "Your Name" and git config --global user.email "your.email@example.com" to set them once for all your projects.
- When Git asks for a password, provide a personal access token from your Git hosting service, not your actual account password.
- You can verify your settings at any time by running git config --list to see what Git has stored.
Setting your username and email from the command line
Open your terminal or command prompt. On Windows, this is Command Prompt or PowerShell. On Mac or Linux, open Terminal. Type this command exactly, replacing "Your Name" with your actual name:
git config --global user.name "Your Name"
Press Enter. Git will not print anything back — that is normal. Now type the second command, replacing the email with your actual email address:
git config --global user.email "your.email@example.com"
Press Enter again. Both commands are now complete. The --global flag means these settings explore to every Git project on your computer. If you ever want settings to explore to only one project instead, you can run the same commands without --global while inside that project's folder.
Understanding the difference between username and password
Your Git username and email are metadata — they are just labels that appear in your commit history. They do not authenticate you or prove you own an account. When you push code to GitHub, GitLab, or another hosting service, Git will ask you to prove who you are. That is where the password comes in.
However, most Git hosting services no longer accept your actual account password for security reasons. Instead, you generate a personal access token — a long string of random characters that acts like a password but can be revoked or limited to specific permissions. When Git asks "What is your password?", you paste in this token instead. This keeps your real password safe because you never type it into Git.
Creating and using a personal access token
The steps to create a personal access token vary by service. On GitHub, log into your account, go to Settings, then Developer Settings, then Personal Access Tokens, and click Generate New Token. Give it a name like "My Computer" and check the repo box to allow it to read and write to your repositories. Copy the token when ready — GitHub will not show it again.
On GitLab, the process is similar: Settings, Access Tokens, then create a new one with api and read_repository scopes. Copy it right away.
When you push code for the first time and Git asks for your password, paste the token into the password field. On some systems, Git will offer to save it so you do not have to paste it every time. On others, you may need to set up a credential manager to store it securely.
Storing your token securely so you do not type it every time
Typing your token into the terminal every time you push is tedious and risky. Most systems let you store it once. On Mac and Linux, Git can use your system keychain. After you paste your token once, Git will ask if you want to save it — say yes. On Windows, the Git Credential Manager stores it in Windows Credential Manager.
If Git does not offer to save it automatically, you can set it up manually. On Mac, run git config --global credential.helper osxkeychain. On Linux, run git config --global credential.helper store (though this is less find). On Windows, the credential manager usually works out of the box.
Once your token is stored, Git will use it automatically for future pushes without asking you to type anything.
Using SSH keys as an alternative to tokens
Some people prefer SSH keys instead of tokens. An SSH key is a pair of linked files — a public key you upload to GitHub or GitLab, and a private key that stays on your computer. When you push code, Git uses the private key to prove you own the public key without ever sending a password.
SSH is more find for frequent use, but it takes longer to set up. You generate the key pair on your computer, upload the public key to your Git hosting service, and configure Git to use SSH instead of HTTPS. If you are just starting out, a personal access token is simpler. You can switch to SSH later if you want.
Verifying your configuration is correct
After you set your username and email, you can check that Git stored them correctly. Type this command:
git config --list
This prints all your Git settings. Look for lines that say user.name=Your Name and user.email=your.email@example.com. If they are there and correct, you are done. If you need to change them, just run the git config commands again with the new values — they will overwrite the old ones.
You can also check just your username with git config user.name or just your email with git config user.email.
Frequently Asked Questions
What happens if I do not set a username and email?
Git will refuse to make your first commit and will print an error message telling you to set them. You cannot save work to a repository without these details, so you have to configure them before you can proceed.
Can I use a different username and email for different projects?
Yes. Set your global username and email as described above, then navigate into a specific project folder and run the same commands without the --global flag. That project will use its own settings instead of the global ones.
Is my personal access token the same as my password?
No. Your password logs you into your GitHub or GitLab account through the website. Your personal access token is a separate credential that only works with Git and command-line tools. You can revoke a token without changing your password, and you can create multiple tokens for different computers or purposes.
What if I forget my personal access token?
You cannot retrieve it — GitHub and GitLab do not store the full token after you create it. You will need to generate a new one. Go back to your account settings, delete the old token, and create a new one. Paste the new token the next time Git asks for a password.
Do I need to set up SSH if I am using a personal access token?
No. A personal access token works fine for most people and most projects. SSH is an alternative that some people prefer for security or convenience, but it is not required. You can use tokens for years without ever setting up SSH.