Git:将文件添加到远程目录会一直失败

问题描述 投票:1回答:1

所以我第一次尝试使用Github。我正在开发一个由项目负责人为我创建的存储库。

我去了我想要的目录

/Users/abrahammathew/Desktop/my_issues

我创建了目录。

Abrahams-MBP:abiomed_issues abrahammathew$ git clone https://github.com/ml_projects/my_repo.git
    ...
    Checking connectivity... done.

初始化已完成

Abrahams-MBP:my_issues abrahammathew$ git init

将文件添加到我的本地存储库

Abrahams-MBP:my_issues abrahammathew$ git add my_data_extraction.py

第一次承诺

Abrahams-MBP:my_issues abrahammathew$ git commit -m "first commit"

远程添加原点。

Abrahams-MBP:abiomed_issues abrahammathew$ git remote add origin https://github.com/abmathewks/my_repo.git

最后,我试图将文件推送到github。

Abrahams-MBP:my_issues abrahammathew$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/abmathewks/my_repo.git/' not found

所以最后一步不行。任何人都可以帮助诊断此问题。我已经指定了正确的回购,所以我不确定为什么没找到它。这是我的本地目录及其内容。

Abrahams-MBP:my_issues abrahammathew$ ls -a
.               my_data_extraction.py
..              my_explore.py
.DS_Store       my_repo
.git

还试过这个:

Abrahams-MBP:my_issues abrahammathew$ git push -u origin:master
ssh: Could not resolve hostname origin: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

一般推动

Abrahams-MBP:my_issues abrahammathew$ git push 
remote: Repository not found.
fatal: repository 'https://github.com/abmathewks/my_repo.git/' not found
git
1个回答
3
投票

部分问题在于您正在执行几个不必要的步骤。其中一些可能相互冲突。

要从头开始创建一个空的repo,请使用

$ git init

要将此新仓库连接到现有仓库,您可以这样做

$ git remote add <name> <URL>

另一方面,当您使用克隆repo时,不需要执行这两个步骤中的任何一个

$ git clone <URL>

这会自动初始化目录以便与git一起使用,并设置一个名为origin的远程引用给定的URL。如果你想添加其他遥控器,那么你可以使用git remote add,其名称不是origin

如果要从GitHub复制现有仓库,您有两种选择:

  1. qazxsw poi创建自己的个人副本。然后qazxsw poi复制到你的本地机器上工作。使用fork的URL。
  2. Fork the GitHub repo原始GitHub回购与原始回购的URL。然后git clone。您可以更改git clone的远程URL: create a new personal repo 或者添加一个新遥控器以指向新的空白回购: origin

正确创建存储库后,根据需要执行以下命令:

$ git remote set-url origin <URL>
© www.soinside.com 2019 - 2024. All rights reserved.