gitlab - 使用https推送,指定用户名和密码

问题描述 投票:3回答:2

我正在尝试将新创建的存储库推送到gitlab。这是我做的:

  1. 在gitlab中创建一个项目。示例网址:https://gitlab.example.com/examples/project1.git
  2. 发起了一个本地裸机: cd ~/projects git init --bare ./project1.git cd project1.git

题:

下一步是将我的所有本地repo推送到gitlab。但我想使用https指定用户名和密码。如何更改以下内容?

git remote add origin https://gitlab.example.com:group1/project1.git
git push --all
git push --tags
git gitlab
2个回答
14
投票

像这里提到的其他人一样,ssh是首选。但对于那些只想使用http / https的用户,可以指定以下凭据:

git remote add origin https://username:[email protected]:group1/project1.git

已验证gitlab 9.0

注意:请用'%40'替换用户名中的'@'符号来处理此问题。


1
投票

当您在gitlab中创建repo时,默认情况下它将使用两个协议ssh和https来克隆git repo。在https中,每次拉或推时它都会提示您的用户凭据。

我更喜欢使用ssh。在ssh中你可以将很多文件推送到repo。在https中,您有大小限制。也许你想推送4gb文件来回购。

请按照以下步骤将ssh设置为remote:

git remote rm https://gitlab.example.com:group1/project1.git

git remote set-url origin ssh://user@host:1234/srv/git/example

有用的信息:

值得一读关于设置git remote:

https://help.github.com/articles/changing-a-remote-s-url/

© www.soinside.com 2019 - 2024. All rights reserved.