git gitlab - 使用 https 推送,指定用户名和密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43069655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gitlab - push using https, specifying username & password
提问by code4kix
I am trying to push a newly created repository to gitlab. Here's what I did:
我正在尝试将新创建的存储库推送到 gitlab。这是我所做的:
Create a project in gitlab. Example URL: https://gitlab.example.com/group1/project1.git
Initiated a local bare repo:
cd ~/projects git init --bare ./project1.git cd project1.git
在 gitlab 中创建一个项目。示例网址:https: //gitlab.example.com/group1/project1.git
启动本地裸仓库:
cd ~/projects git init --bare ./project1.git cd project1.git
Question:
题:
Next step is to push all of my local repo into gitlab. But I want to specify username and password using https. How do I change the following to do it?
下一步是将我所有的本地存储库推送到 gitlab。但我想使用 https 指定用户名和密码。我如何更改以下内容来做到这一点?
git remote add origin https://gitlab.example.com:group1/project1.git
git push --all
git push --tags
回答by code4kix
Like others mentioned here, ssh is preferred. But for those you want to use just http/https, you can specify credentials like this:
像这里提到的其他人一样,ssh 是首选。但是对于那些您只想使用 http/https 的用户,您可以指定如下凭据:
git remote add origin https://username:[email protected]:group1/project1.git
Verified for gitlab 9.0
已针对 gitlab 9.0 进行验证
Note: Please replace '@' symbols in username with '%40' to work this.
注意:请将用户名中的 '@' 符号替换为 '%40' 以解决此问题。
回答by danglingpointer
When you created the repo in gitlab, by deafault it will provide to clone git repo using two protocols, ssh and https. Where in https it will prompt your user credential every time you pull or push.
当你在 gitlab 中创建 repo 时,默认情况下它会提供使用两种协议克隆 git repo,ssh 和 https。在 https 中,每次拉或推时都会提示您的用户凭据。
I prefer to use ssh. Where as in ssh you can push lot of files to repo. In https you have size restriction. Perhaps you want push 4gb files to repo.
我更喜欢使用 ssh。在 ssh 中,您可以将大量文件推送到 repo。在 https 中,您有大小限制。也许您想将 4gb 文件推送到 repo。
Follow these steps to set ssh as remote:
按照以下步骤将 ssh 设置为远程:
git remote rm https://gitlab.example.com:group1/project1.git
git remote set-url origin ssh://user@host:1234/srv/git/example
Useful information:
有用的信息:
Worth reading about setting up git remote:
关于设置 git remote 值得一读: