git 无法克隆或推送现有项目到 gitlab
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50299094/
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
not able to clone or push existing project to gitlab
提问by reddy
I have created one private repo, and I have the existing project on my laptop. I need to add the existing project to my repo. But when I do with terminal I am getting this below error :
我创建了一个私人仓库,我的笔记本电脑上有现有的项目。我需要将现有项目添加到我的仓库中。但是当我使用终端时,我收到以下错误:
remote: The project you were looking for could not be found.
fatal: repository 'https://gitlab.com/sathishchinniah/Taxi-App-User.git/' not found
Steps I followed :
我遵循的步骤:
**Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/sathishchinniah/Taxi-App-User.git
git add .
git commit -m "Initial commit"
git push -u origin master**
What would be an issue for this.Please help me out.Thanks
这会是什么问题。请帮帮我。谢谢
回答by coder
Below step solved my problem. In below command replace username
with your GitLab username and project
with your GitLab project name.
下面的步骤解决了我的问题。在下面的命令中替换username
为您的 GitLab 用户名和project
您的 GitLab 项目名称。
git remote set-url origin https://[email protected]/username/project.git
After you try to push to the master using bellow command it will popup a window to add credential to the repository.
在您尝试使用 bellow 命令推送到 master 后,它将弹出一个窗口以将凭据添加到存储库。
git push -u origin master
回答by muecas
The problem is that you are not referencing the repository as you should for gitlab. Instead of:
问题是您没有像 gitlab 那样引用存储库。代替:
https://gitlab.com/sathishchinniah/Taxi-App-User.git
You should use:
你应该使用:
[email protected]:sathishchinniah/Taxi-App-User.git
Gitlab uses a single defined user for cloning, pushes and pulls (and every action related) and authenticates the action thru ssh keys. You should have one for the computer you are using (the one with your working copy) and register the key as a valid key for the repository on gitlab.
Gitlab 使用单个定义的用户进行克隆、推送和拉取(以及所有相关操作)并通过 ssh 密钥验证操作。您应该为您正在使用的计算机(带有工作副本的计算机)准备一个,并将该密钥注册为 gitlab 上存储库的有效密钥。
First, you need to have a user defined on your local git. If not, you can do as follows to configure yours:
首先,您需要在本地 git 上定义一个用户。如果没有,您可以执行以下操作来配置您的:
- Set up your name using
git config --global user.name "Your name here"
- Set up your email; the email must be enabled for the repository, and needs to have a private key added on the repository for permission purposes .
git config --global user.email "[email protected]"
- 使用设置你的名字
git config --global user.name "Your name here"
- 设置您的电子邮件;必须为存储库启用电子邮件,并且需要在存储库中添加私钥以用于权限目的。
git config --global user.email "[email protected]"
Then you should create and register you key. I can further assist you with that too if you need.
然后您应该创建并注册您的密钥。如果您需要,我也可以进一步协助您。
Then, depending on what you want to do or how you want to start, you have a few options:
然后,根据您想要做什么或如何开始,您有几个选择:
Option 1
选项1
Clone an existing repository:
克隆现有的存储库:
- Clone the repository:
git clone [email protected]:namespace/project.git
where “namespace” is the namespace of your group of projects, or your gitlab user (if no groups are defined) and “project” is the name of your project over gitlab - Then you can simply add some files, commit them and push the commit by running:
git push -u origin master
- 克隆存储库:
git clone [email protected]:namespace/project.git
其中“namespace”是您的项目组或您的 gitlab 用户(如果未定义组)的名称空间,“project”是您在 gitlab 上的项目名称 - 然后你可以简单地添加一些文件,提交它们并通过运行来推送提交:
git push -u origin master
Option 2
选项 2
Initialize the repository locally and then push the content to server:
在本地初始化存储库,然后将内容推送到服务器:
- Initialize the repository:
git init
- Add the remote:
git remote add origin [email protected]:namespace/project.git
where “namespace” is the namespace of your group of projects, or your gitlab user (if no groups are defined) and “project” is the name of your project over gitlab - Then you can simply add some files, commit them and push the commit by running:
git push -u origin master
- 初始化存储库:
git init
- 添加远程:
git remote add origin [email protected]:namespace/project.git
其中“namespace”是您的项目组或您的 gitlab 用户(如果未定义组)的名称空间,“project”是您在 gitlab 上的项目名称 - 然后你可以简单地添加一些文件,提交它们并通过运行来推送提交:
git push -u origin master
Option 3
选项 3
Use an existing local repository:
使用现有的本地存储库:
- Rename the old origin (if necessary):
git remote rename origin old-origin
- Add the new origin:
git remote add origin [email protected]:namespace/project.git
where “namespace” is the namespace of your group of projects, or your gitlab user (if no groups are defined) and “project” is the name of your project over gitlab - Push your branches:
git push -u origin --all
andgit push -u origin --tags
to push all tags
- 重命名旧原点(如有必要):
git remote rename origin old-origin
- 添加新来源:
git remote add origin [email protected]:namespace/project.git
其中“namespace”是您的项目组或您的 gitlab 用户(如果未定义组)的名称空间,“project”是您在 gitlab 上的项目名称 - 推送你的分支:
git push -u origin --all
并git push -u origin --tags
推送所有标签
In your case you would like to use a new empty repository initialized locally and then push the content to repository:
在您的情况下,您希望使用在本地初始化的新的空存储库,然后将内容推送到存储库:
git init
git remote add origin [email protected]:sathishchinniah/Taxi-App-User.git
git add .
git commit -m "Initial commit"
git push -u origin master
If it fails, please provide the errors. You should check also if you have a private key defined in your computer, and if the key is defined as a valid key for your repository at gitlab.
如果失败,请提供错误信息。您还应该检查您的计算机中是否定义了私钥,以及该密钥是否被定义为 gitlab 中存储库的有效密钥。
Hope it helps.
希望能帮助到你。
回答by J. Burke
Since this is a private repository, you'll need to provide credentials for this server. Try :
由于这是一个私有存储库,您需要为此服务器提供凭据。尝试 :
git remote add origin ssh://[email protected]/sathishchinniah/Taxi-App-User.git
or
或者
git remote add origin https://[email protected]/sathishchinniah/Taxi-App-User.git
It should prompt for the password.
它应该提示输入密码。
回答by Keshav Gera
Set up your name using git config --global user.name "Your name here"
使用 git config --global user.name "Your name here" 设置你的名字
Set up your email; the email must be enabled for the repository, and needs to have a
设置您的电子邮件;必须为存储库启用电子邮件,并且需要具有
private key added on the repository for permission purposes . git config --global user.email "[email protected]"
出于许可目的,在存储库中添加了私钥。git config --global user.email "[email protected]"
before:
前:
https://gitlab.com/{gitlab_user}/project_repo.git
https://gitlab.com/{gitlab_user}/project_repo.git
after:
后:
https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git
https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git
回答by Vikram Kodag
I solved this issue by,
我解决了这个问题,
git remote set-url origin https://<USERNAME>:<PASSWORD>@<gitlab host>/path/to/repo.git
For Example
例如
git remote set-url origin https://Vikram:*********@gitlab.info.lab/testdemo/mydemo.git
回答by Adarsh Singhal
Approach #1
方法#1
While cloning the code Gitlab, add your credentials in the URL:-
在克隆代码 Gitlab 时,在 URL 中添加您的凭据:-
git clone https://{username}:{password}@gitlab.com/.../
But this is not good from the security perspective.
但这从安全的角度来看并不好。
Approach #2
方法#2
If you are using windows, then delete the existing entries for gitlab in Windows Credential Manager. This is present under Control Panel.
如果您使用的是 Windows,则在 Windows Credential Manager 中删除 gitlab 的现有条目。这存在于控制面板下。
After deleting the credential, clone the repository again, you should see a window asking for credentials.
删除凭据后,再次克隆存储库,您应该会看到一个要求凭据的窗口。
In my case, the root cause is that I was trying to access the repository from a different account which was saved in Windows Credential Manager.
就我而言,根本原因是我试图从保存在 Windows 凭据管理器中的不同帐户访问存储库。