-4

I stored my credentials inside ~/.gitconfig using the following commands:

git config --global user.name "MauroTheCreator"
git config --global user.email "myemail@gmail.com"

But when I commit data to a branch and push the data, it take my credentials again

I commit using

git add stuff
git commit
git push

This is really anoying, how can i fix it?

Mort
  • 3,379
  • 1
  • 25
  • 40
  • Does this answer your question? [How to save username and password in Git?](https://stackoverflow.com/questions/35942754/how-to-save-username-and-password-in-git) – theodoreh Mar 30 '21 at 10:51
  • 5
    What you've set in `.gitconfig` is the metadata to add to the `git commit`s you make. That is **not** the same thing as the credentials to use for requests to `git push` to the remote (e.g. BitBucket, GitHub, GitLab). – jonrsharpe Mar 30 '21 at 10:51

1 Answers1

1

Git uses credential helpers behind the scene to store your credentials. You can check which credential-helper is configured on your system by running git config --list and lookin up for credential.helper or by just running git config credential.helper.

On windows, older versions of git(before Git 2.29) use Git Credential Manager For Windows and have default helper set as credential.helper=manager whereas, newer Git releases( Git 2.29 or later) use Git Credential Manager Core and have the default helper configured as credential.helper=manager-core.

I don't have any experience working with OSX, but as far as the online sources say, the git config credential.helper returns credential.helper=osxkeychain.

You can tell git to store credentials by running the git credential approve command followed by key-value pairs of protocol, host, username and password :

git credential approve
protocol=https
host=github.com
username=<user-name>
password=<pwd/token>
Hit RETURN/ENTER key Twice

Your credentials should now be saved.

You can confirm that by running git fill command:

git credential fill
protocol=https
host=github.com
Hit RETURN/ENTER Key twice

Running the above should return the credentials. I have a windows system. But since git's commands should work almost the same on any OS, this should work fine on Mac as well.

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47