185

I am using Git Bash on Windows 7. We are using GitHub as our repository origin.

Every time I push or pull I have to provide user and password credentials. I know that my SSH keys are set up correctly, otherwise I would not be able to access the repository. (That is, once I enter my credentials the push/pull works correctly.)

I have entered

git config --global user.name myusername
git config --global user.email myemail
git config --global github.user myusername
git config --global github.token mytoken

But nonetheless I am being asked for credentials each and every time I push/pull.

2

14 Answers 14

124

From Git Bash I prefer to run the command:

git config --global credential.helper wincred

At that point running a command like git pull and entering your credentials one time should have it stored for future use. Git has a built-in credentials system that works in different OS environments. You can get more details here: 7.14 Git Tools - Credential Storage

Sign up to request clarification or add additional context in comments.

7 Comments

Is there a linux alternative, or does this work for linux too ?
git config --global credential.helper cache help.github.com/en/github/using-git/…
@SoldOut you know where the term "bash" in "git bash" stems from, right?
@clockw0rk Oh, yes sure - thank you for the good hint. I just... that git versions do differ quite substantialy even on same OS, so I thought here might be difference for UX derivate systems too.
what does wincred do?
|
120

Make sure you are using the SSH URL for the GitHub repository rather than the HTTPS URL. It will ask for username and password when you are using HTTPS and not SSH. You can check the file .git/config or run git config -e or git remote show origin to verify the URL and change it if needed.

You can change the URL with: [1]

git remote set-url origin git+ssh://[email protected]/username/reponame.git

[1] This portion incorporates the answer to this question.

4 Comments

I cannot use SSH because of internal firewall rules (don't ask...) Is there another way to let git login automatically?
@Jorn not being able to change the ports used for SSH is a right pain in the bum.
Is the git+ssh:// useful? I tried and got an error but removing it and then pushing it worked.
Finally something that works !
102

For those who are using access token and a Windows environment, there is a simple way to do it:

Start menu → Credential ManagerWindows Credentials → find the line (Git: https://whatever/your-repository/url) → edit, user name is "github_username" and password is your access token.

3 Comments

I have multiple git accounts for diff companies I work with, I guess there isn't a way to store more than one in the credential manager?
user name is "github username"
This was usefull to setup the value to use, but to tell git to use this manager follow @IcedDante or @notreadbyhumans answer: git config --global credential.helper wincred
25

If you are a Mac user and have keychain enabled, you to need to remove the authorization information that is stored in the keychain:

- Open up Keychain access
- Click "All items" under category in the left-hand column
- Search for git
- Delete all git entries.

Then you should change your username and email from the terminal using git config:

$ git config --global user.name "Bob"

$ git config --global user.email "[email protected]"

Now if you try to push to the repository you will be asked for a username and password. Enter the login credentials you are trying to switch to. This problem normally pops up if you signed into GitHub on a browser using a different username and password or previously switched accounts on your terminal.

1 Comment

This helped me. Although, there is no need to delete the git entries, you can edit them right there.
18

I wrote an answer in this other answer: How to change git account in Git bash?

Still, I am sharing it here as well.

Change username and email global

git config --global user.name "<username>"
git config --global user.email "<email>"

Change username and email for current repo

git config  user.name "<username>" --replace-all
git config  user.email "<email>" --replace-all

Comments

13

With git bash for Windows, the following combination of the other answers worked for me (repository checked out using the GitHub client i.e. https, not ssh):

  1. Generate a Personal Access Token
  2. Start a git bash session within your repo
  3. run git config --global credential.helper wincred
  4. run git pull
  5. give PersonalAccessToken as the username
  6. give the Personal Access Token as the password

Comments

8

add remote as:

git remote add https://username:[email protected]/repodir/myrepo.git

3 Comments

It is now git remote add <name> <url>
@LoganGeorge What is <name> exactly?
@A__ the name you want to set for the remote, eg origin
8

First Store username name password globally, By using this command

git config --global github.user <your_username>

then use this command

git config --global credential.helper store

Comments

3

If the git bash is not working properly due to recently changed password.

You could open the Git GUI, and clone from there. It will ask for password, once entered, you can close the GIT GUI window.

Now the git bash will work perfectly.

Comments

2

Try ssh-agent for installing the SSH key for use with Git. It should auto login after use of a passphrase.

Comments

1

GnuPG can be used as cross-platform password manager, including GIT HTTPS credetials. Just use your GPG key-pair to encrypt/decrypt passwords(tokens...). To encrypt token(password) run:

gpg -e -o [PATH_TO_ENCRYPTED_TOKEN] -r "[GPG_KEY_USER_ID]"

type the token (or copy-paste it) then press Ctrl+D for ending input, or use file name with this token. Then make custom git credential helper: BASH file with name git-credential-[HELPER_LAST_NAME] (without SH extension):

#!/bin/bash
token=`gpg -d -r "[GPG_KEY_USER_ID]" [PATH_TO_ENCRYPTED_TOKEN] 2>/dev/null`
echo protocol=https
echo host=[YOUR_HOST]
echo username=[YOUR_USER_NAME]
echo password=$token

On MS-WINDOWS in GIT-BASH path names must use UNIX file separator - "/", just run in git-bash "echo $PATH"! Then put the helper into place as in $PATH. Then add and check the helper:

git config --global credential.helper [HELPER_LAST_NAME]
#then check it (password will be printed as plain text!!!):
git credential-[HELPER_LAST_NAME]

GnuPG can be used as password manager in Maven projects instead of Maven's password-encryption method. And so on.

Comments

0

If your repo is of HTTPS repo, git config -e give this command in the git bash. Update the username and password by opening in insert mode, change the password or username give :x and Cntrl+z keys it will save and exit

So, From then while you pull / push the code to the repository it will not ask for password.

Comments

0

Very Simple Solution, you have to use quotations:

git config --global user.name "your name" 

Comments

0

If you have not tried this option. It solves the issue of configuring username and password on Git Bash. Namely, being able to git push to your repo.

$ git init
$ git config user.name "yourusername"
$ git config user.email "[email protected]"
$ git add *
$ git commit -m "msg to be committed"
$ git push origin master/main

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.