Git:将文件添加到远程目录会导致

时间:2018-01-01 20:33:47

标签: git

所以我第一次尝试使用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

1 个答案:

答案 0 :(得分:3)

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

要从头开始创建空仓库,请使用

$ git init

要将此新仓库连接到现有仓库,您可以执行

$ git remote add <name> <URL>

另一方面,当您使用

克隆回购时,您不需要执行这两个步骤中的任何一个步骤
$ git clone <URL>

这会自动初始化目录以供git使用,并设置一个名为origin的远程引用给定的URL。如果您要添加其他遥控器,则可以git remote add使用origin以外的名称。

如果您想从GitHub复制现有的仓库,您有两个选择:

  1. Fork the GitHub repo创建自己的个人副本。然后git clone复制到本地计算机以进行操作。使用fork的URL。

  2. git clone原始GitHub回购,其中包含原始回购的网址。然后是create a new personal repo。您可以更改origin的远程网址:

    $ git remote set-url origin <URL>
    

    或添加新遥控器以指向新的空白仓库:

    $ git remote add my-personal-repo <URL>
    
  3. 正确创建存储库后,根据需要执行以下命令:

    $ git add <file name>
    $ git commit -m 'Some message'
    $ git push
    
相关问题