After reading the thread in full and experimenting with most of the answers to this question, I eventually found the procedure that works for me. I want to share it in case someone has to deal with a complex use case but still do not want to go through the full thread and the gitcredentials, gitcredentials-store etc. man pages, as I did.
Find below the procedure I suggest IF you (like me) have to deal with several repositories from several providers (GitLab, GitHub, Bitbucket, etc.) using several different username / password combinations. If you instead have only a single account to work with, then you might be better off employing the git config --global credential.helper store
or git config --global user.name "your username"
etc. solutions that have been very well explained in previous answers.
My solution:
> git config --global --unset credentials.helper
> cd /path/to/my/repo
> git config --unset credential.helper
> git config credential.helper 'store --file ~/.git_repo_credentials'
Note: this command creates a new file named ".git_repo_credentials" into your home directory, to which Git stores your credentials. If you do not specify a file name, Git uses the default ".git_credentials". In this case simply issuing the following command will do:
> git config credential.helper store
git config credential.*.username my_user_name
Note: using "*" is usually ok if your repositories are from the same provider (e.g. GitLab). If instead your repositories are hosted by different providers then I suggest to explicitly set the link to the provider for every repository, like in the following example (for GitLab):
git config credential.https://gitlab.com.username my_user_name
At this point if you issue a command requiring your credentials (e.g. git pull
) you will be asked for the password corresponding to "my_user_name". This is only required once because git stores the credentials to ".git_repo_credentials" and automatically uses the same data at subsequent accesses.