Is there a way to cache GitHub credentials for pushing commits?

后端 未结 24 3261
囚心锁ツ
囚心锁ツ 2020-11-21 05:02

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

相关标签:
24条回答
  • 2020-11-21 05:14

    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 to true 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 the git 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.

    0 讨论(0)
  • 2020-11-21 05:15

    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
    
    0 讨论(0)
  • 2020-11-21 05:15

    You can use credential helpers.

    git config --global credential.helper 'cache --timeout=x'
    

    where x is the number of seconds.

    0 讨论(0)
  • 2020-11-21 05:16

    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.

    0 讨论(0)
  • 2020-11-21 05:17

    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.

    0 讨论(0)
  • 2020-11-21 05:22

    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.

    0 讨论(0)
提交回复
热议问题