Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring user and password with Git Bash

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.


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


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.


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.


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

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