1. 程式人生 > 實用技巧 >github配置:為命令列建立個人訪問令牌

github配置:為命令列建立個人訪問令牌

命令列或API上使用Git通過HTTPS執行Git操作時,可以建立一個個人訪問令牌並用它代替密碼。

In this article

A personal access token is required to authenticate to GitHub in the following situations:

As a security precaution, GitHub automatically removes personal access tokens that haven't been used in a year.

Creating a token

  1. 驗證您的電子郵箱地址,(如果尚未驗證)。

  2. 在任何頁面的右上角,單擊您的個人資料照片,然後單擊設定。

  3. 在左側邊欄中,單擊“開發人員設定”。

  4. In the left sidebar, clickPersonal access tokens.

  5. ClickGenerate new token.

  6. Give your token a descriptive name.

  7. Select the scopes, or permissions, you'd like to grant this token. To use your token to access repositories from the command line, selectrepo.

  8. ClickGenerate token.

  9. Clickto copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.

    Warning:Treat your tokens like passwords and keep them secret. When working with the API, use tokens as environment variables instead of hardcoding them into your programs.

  10. To use your token to authenticate to an organization that uses SAML SSO,authorize the token for use with a SAML single-sign-on organization.

Using a token on the command line

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.

For example, on the command line you would enter the following:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need toswitch the remote from SSH to HTTPS.

If you are not prompted for your username and password, your credentials may be cached on your computer. You canupdate your credentials in the Keychainto replace your old password with the token.