I recently switched to synchronizing my repositories to https:// on GitHub (due to firewall issues), and it asks for a password every time.
Is there a way to cache t
The composer documentation mentions that you can prevent it from using the GitHub API, so that it acts like git clone
:
If you set the
no-api
key totrue
on a GitHub repository it will clone the repository as it would with any other Git repository instead of using the GitHub API. But unlike using thegit
driver directly, composer will still attempt to use GitHub's zip files.
So the section would look like this:
"repositories": [
{
"type": "vcs",
"no-api": true,
"url": "https://github.com/your/repo"
}
],
Keep in mind that the API is there for a reason. So it this should be a method of last resort regarding the increased load on github.com.
Use a credential store.
For Git 2.11+ on OS X and Linux, use Git's built in credential store:
git config --global credential.helper libsecret
For msysgit 1.7.9+ on Windows:
git config --global credential.helper wincred
For Git 1.7.9+ on OS X use:
git config --global credential.helper osxkeychain
You can use credential helpers.
git config --global credential.helper 'cache --timeout=x'
where x
is the number of seconds.
After you clone repository repo
, you can edit repo/.git/config
and add some configuration like below:
[user]
name = you_name
password = you_password
[credential]
helper = store
Then you won't be asked for username
and password
again.
It is better to use credentials for security, but you can keep it for some time using the cache:
git config --global credential.helper cache
git config credential.helper 'cache --timeout=3600'
Your credentials will be saved for 3600 seconds.
If you are using osxkeychain
and had a token expire and want to update it, follow these steps:
Run in terminal, then press enter twice.
git credential-osxkeychain erase
host=github.com
protocol=https
Now you should be prompted for a username/password. However sometimes it seems this does not 'take' and you have to keep re-entering.
If so, restart your computer. Now the next time you run a git command and enter your username/password, it will be saved.