如何在私人项目 gitlab 中使用个人访问令牌通过 https 进行 git 克隆

Oma*_*MOS 4 authentication cmd gitlab

我想在我的 mac 上 git 克隆一个具有两因素身份验证的私有存储库,我的 gitlab 中已经有一个个人访问令牌,并且我正在尝试找到在 vscode 终端上运行的正确命令。

omarfuentes@192 ~ % git 克隆https://gitlab.com/OmarLeonardo/frappe/proyectos/frappe-oms/frappe-server.git?personal_access_token=myaccesstoken

但答案是: zsh:找不到匹配项: https: //gitlab.com/OmarLeonardo/frappe/proyectos/frappe-oms/frappe-server.git ?personal_access_token=myaccesstoken

Von*_*onC 9

如果您使用具有正确范围的PAT(个人访问令牌) ,您应该使用:

git clone https://<my-user-id>:<my-token>@gitlab.com/<my-account>/<my-project-name>.git
# or
git clone https://oauth2:<my-token>@gitlab.com/<my-account>/<my-project-name>.git
Run Code Online (Sandbox Code Playgroud)

这将避免需要对参数进行 URL 编码。

但为了避免直接在远程 URL 中公开令牌,请考虑使用凭证存储