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

后端 未结 24 3384
囚心锁ツ
囚心锁ツ 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:04

    An authentication token should be used instead of the account password. Go to GitHub settings/applications and then create a personal access token. The token can be used the same way a password is used.

    The token is intended to allow users not use the account password for project work. Only use the password when doing administration work, like creating new tokens or revoke old tokens.


    Instead of a token or password that grants a user whole access to a GitHub account, a project specific deployment key can be used to grant access to a single project repository. A Git project can be configured to use this different key in the following steps when you still can access other Git accounts or projects with your normal credential:

    1. Write an SSH configuration file that contains the Host, IdentityFile for the deployment key, maybe the UserKnownHostsFile, and maybe the User (though I think you don't need it).
    2. Write an SSH wrapper shell script that virtually is ssh -F /path/to/your/config $*
    3. Prepend GIT_SSH=/path/to/your/wrapper in front of your normal Git command. Here the git remote (origin) must use the git@github.com:user/project.git format.

提交回复
热议问题