无法将现有项目克隆或推送到GitLab。

8

我创建了一个私有仓库,并且我已经在我的笔记本电脑上有现有的项目。我需要将现有的项目添加到我的仓库中。但是当我使用终端进行操作时,我遇到了以下错误:

remote: The project you were looking for could not be found.
fatal: repository 'https://gitlab.com/sathishchinniah/Taxi-App-User.git/' not found

我遵循的步骤:

**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**

这可能是一个问题。请帮我解决,谢谢。

只需登录GitLab,进入存储库,并按照说明进行克隆、推送/添加远程操作。 - muecas
7个回答

17

以下步骤解决了我的问题。在下面的命令中,将username替换为您的GitLab用户名,将project替换为您的GitLab项目名称。

git remote set-url origin https://username@gitlab.com/username/project.git
尝试使用以下命令推送到主分支后,系统将弹出一个窗口要求您添加存储库的凭据。
git push -u origin master

3
问题在于您没有按照gitlab的要求引用存储库。应该使用以下方式而不是:
https://gitlab.com/sathishchinniah/Taxi-App-User.git

您应该使用:

git@gitlab.com:sathishchinniah/Taxi-App-User.git

Gitlab使用一个预定义的用户进行克隆、推送和拉取(以及所有相关操作)并通过ssh密钥验证操作。你应该为你正在使用的计算机(带有你的工作副本)创建一个用户,并将该密钥注册为gitlab存储库的有效密钥。
首先,你需要在本地Git上定义一个用户。如果没有,请按以下方式配置:
1. 使用“git config --global user.name "Your name here"”设置您的姓名 2. 设置您的电子邮件;电子邮件必须启用存储库,并需要在存储库上添加私钥以获取权限 git config --global user.email "your@mail.com" 然后,你应该创建并注册你的密钥。如果需要,我可以为你提供进一步的协助。
接下来,根据你想做什么或如何开始,你有几个选择:
选项1: 克隆现有存储库: 1. 克隆存储库:git clone git@gitlab.com:namespace/project.git,其中“namespace”是你的项目组的命名空间,或者是你的gitlab用户(如果没有定义组),而“project”是你在gitlab上的项目名称。 2. 然后,你可以简单地添加一些文件,提交它们,并通过运行“git push -u origin master”来推送提交。
选项2: 在本地初始化存储库,然后将内容推送到服务器: 1. 初始化存储库:git init 2. 添加远程地址:git remote add origin git@gitlab.com:namespace/project.git,其中“namespace”是你的项目组的命名空间,或者是你的gitlab用户(如果没有定义组),而“project”是你在gitlab上的项目名称。 3. 然后,你可以简单地添加一些文件,提交它们,并通过运行“git push -u origin master”来推送提交。
选项3: 使用现有的本地存储库: 1. 重命名旧原点(如果需要):git remote rename origin old-origin 2. 添加新源:git remote add origin git@gitlab.com:namespace/project.git,其中“namespace”是你的项目组的命名空间,或者是你的gitlab用户(如果没有定义组),而“project”是你在gitlab上的项目名称。 3. 推送你的分支:git push -u origin --all和git push -u origin --tags以推送所有标记。
在你的情况下,你想使用一个本地初始化的新空存储库,然后将内容推送到存储库。
git init
git remote add origin git@gitlab.com:sathishchinniah/Taxi-App-User.git
git add .
git commit -m "Initial commit"
git push -u origin master

如果失败,请提供错误信息。您还应该检查计算机上是否定义了私钥,并且该密钥是否被定义为gitlab存储库的有效密钥。
希望这有所帮助。

2

方法一

在克隆Gitlab代码时,在URL中添加您的凭据:

git clone https://{username}:{password}@gitlab.com/.../

但是从安全角度来看,这种方法并不好。

第二种方法

如果您使用的是Windows,则需要在控制面板下删除Windows凭据管理器中gitlab的现有条目。

enter image description here

在删除凭据后,再次克隆存储库,应该会出现请求凭据的窗口。

在我的情况下,根本原因是我正在尝试从另一个保存在Windows凭据管理器中的帐户访问存储库。


1

由于这是一个私有仓库,您需要提供此服务器的凭据。请尝试:

git remote add origin ssh://sathishchinniah@gitlab.com/sathishchinniah/Taxi-App-User.git

or

git remote add origin https://sathishchinniah@gitlab.com/sathishchinniah/Taxi-App-User.git

它应该提示输入密码。

我需要使用 git remote add origin https://username@gitlab.com/username/repo.git 这一行代替 git remote add origin https://gitlab.com/sathishchinniah/Taxi-App-User.git - reddy
请尝试我添加的示例(您的用户名不是“username”)。确保在 .git 后面没有 /。 - J. Burke

1
如果您在任何代码编辑器(例如Android Studio或VS Code)中配置了多个帐户,则需要在推送之前在远程URL之前使用您的用户名,如下所示。
git remote set-url origin https://username@gitlab.com/username/project.git

然后

git push -u origin master

否则就不需要添加用户名,您可以像平常一样按照以下方式推送。
git init
git remote add origin https://@gitlab.com/username/project.git
git add .
git commit -m "Initial commit"
git push -u origin master*

0

使用 git config --global user.name "你的名字" 来设置你的名称

设置你的邮箱;邮箱必须启用仓库,并需要添加到仓库的私有密钥以获取权限。使用 git config --global user.email "your@mail.com"

之前:

https://gitlab.com/{gitlab_user}/project_repo.git

之后:

https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git

更多细节


0

我通过以下方式解决了这个问题:

git remote set-url origin https://<USERNAME>:<PASSWORD>@<gitlab host>/path/to/repo.git

例如

git remote set-url origin https://Vikram:*********@gitlab.info.lab/testdemo/mydemo.git

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接