How to enter command with password for git pull?
How to do it?
4 Solutions collect form web for “How to enter command with password for git pull?”
This is not exactly what you asked for, but for http(s):
- you can put the password in .netrc file (_netrc on windows). From there it would be picked up automatically. It would go to your home folder with 600 permissions.
- you could also just clone the repo with
https://user:pass@domain/repobut that’s not really recommended as it would show your user/pass in a lot of places…
- a new option is to use the credential helper. Note that credentials would be stored in clear text in your local config using standard credential helper. credential-helper with wincred can be also used on windows.
Usage examples for credential helper
git config credential.helper store– stores the credentials indefinitely.
git config credential.helper 'cache --timeout=3600'– stores for 60 minutes
For ssh-based access, you’d use ssh agent that will provide the ssh key when needed. This would require generating keys on your computer, storing the public key on the remote server and adding the private key to relevant keystore.
I found one way to supply credentials for a https connection on the command line. You just need to specify the complete URL to git pull and include the credentials there:
git pull https://username:firstname.lastname@example.org/my/repository
You do not need to have the repository cloned with the credentials before, this means your credentials don’t end up in
.git/config. (But make sure your shell doesn’t betray you and stores the command line in a history file.)
Doesn’t answer the question directly, but I found this question when searching for a way to, basically, not re-enter the password every single time I pull on a remote server.
git allows you to cache your credentials for a finite amount of time. It’s customizable in
git config and this page explains it very well:
In a terminal, run:
$ git config --global credential.helper cache # Set git to use the credential memory cache
To customize the cache timeout, you can do:
$ git config --global credential.helper 'cache --timeout=3600' # Set the cache to timeout after 1 hour (setting is in seconds)
Your credentials will then be stored in-memory for the requested amount of time.
Note that the way the git credential helper “store” will store the unencrypted passwords changes with Git 2.5+ (Q2 2014).
See commit 17c7f4d by Junio C Hamano (
Tweak the sample “
store” backend of the credential helper to honor XDG configuration file locations when specified.
The doc now say:
If not specified:
- credentials will be searched for from
- credentials will be written to
~/.git-credentialsif it exists, or
$XDG_CONFIG_HOME/git/credentialsif it exists and the former does not.