git 如何在 GitHub 上提交并推送到其他人的存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21369917/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:38:26  来源:igfitidea点击:

How can I commit and push to someone else's repository on GitHub?

gitgithub

提问by Arnold

I have cloned a repository created by a professor on my virtual machine (I'm running Ubuntu 13.10) and we're supposed to create personal folders. I created mine, but I cannot for the life of me commit and push it to make it show up on GitHub. I swear I have tried every answer on here, and things have improved somewhat. For instance, I originally had a version of Git that was too old and wouldn't permit https. I also created a blank file in my personal directory because I know GitHub doesn't store empty folders.

我在我的虚拟机(我正在运行 Ubuntu 13.10)上克隆了一个教授创建的存储库,我们应该创建个人文件夹。我创建了我的,但我不能在我的一生中提交并推送它以使其显示在 GitHub 上。我发誓我已经尝试了这里的所有答案,并且情况有所改善。例如,我最初有一个太旧的 Git 版本,不允许使用 https。我还在我的个人目录中创建了一个空白文件,因为我知道 GitHub 不存储空文件夹。

I originally cloned the repository using:

我最初使用以下方法克隆了存储库:

$ git clone git://github.com/astrofoley/astr596.git 

And then used

然后用

git config --global user.name "myusername"

and

git config --global user.email "myemail"

I checked with my professor and he made sure I have adequate permissions.

我咨询了我的教授,他确保我有足够的权限。

At this point, depending upon which commit and push methods I use (I always try to push to https://github.com/astrofoley/astr596.git), I get several different errors ranging from "nothing added to commit but untracked files present" to simply "403". I have no idea what I am doing wrong, but I suspect it is something related to the fact that the repository belongs to another account. Either way, this is getting incredibly frustrating. Please help!

在这一点上,根据我使用的提交和推送方法(我总是尝试推送到https://github.com/astrofoley/astr596.git),我收到几个不同的错误,从“没有添加到提交但未跟踪的文件现在”到简单的“403”。我不知道我做错了什么,但我怀疑这与存储库属于另一个帐户的事实有关。无论哪种方式,这都令人难以置信地令人沮丧。请帮忙!

EDIT: Here's an example of my current problem. I tried adding and committing the file in my directory again using

编辑:这是我当前问题的一个例子。我尝试使用

git add blank.txt

(this step seems to have worked fine) and then

(这一步似乎工作得很好)然后

git commit blank.txt

At this point I get the message "On branch master, nothing to commit, working directory clean".

此时,我收到消息“在分支主控上,无需提交,工作目录干净”。

采纳答案by Arnold

RESOLVED. I deleted and recloned the directory now that I have collaborator permissions. This was definitely the way to go because it removed the failed ssh keys and all of the different configurations I'd been experimenting with. Once everything was recloned, I re-made my directory, put a blank file in it, git added the directory and then the file, committed my change from the astr596 repository, and pushed to origin. Success!

解决。既然我拥有合作者权限,我就删除并重新克隆了该目录。这绝对是要走的路,因为它删除了失败的 ssh 密钥和我一直在试验的所有不同配置。重新克隆所有内容后,我重新创建了我的目录,在其中放入一个空白文件,git 添加了目录,然后添加了文件,从 astr596 存储库提交了我的更改,然后推送到了源。成功!

回答by asmacdo

Just to make it comprehensive,

只是为了让它全面,

  1. Make a change.

    touch somefile.txt
    
  2. tell git to track this change

    git add somefile.txt
    
  3. commit the change

    git commit -m "what you did"
    
  4. set up your remote.

  5. push

    git push <remote> <branch>
    
  1. 做出改变。

    touch somefile.txt
    
  2. 告诉 git 跟踪此更改

    git add somefile.txt
    
  3. 提交更改

    git commit -m "what you did"
    
  4. 设置您的遥控器

  5. git push <remote> <branch>
    

回答by Fernando

Are you added as a collaborator in your professor's repo? If you are working from a linux terminal you must give your professor a id_rsa.pubfile to add you as collaborator (since the terminal is not synced with your github account, which actually happens if you use the GUI versions of github for win or mac).

你在教授的 repo 中被添加为合作者吗?如果您使用 linux 终端工作,您必须给您的教授一个id_rsa.pub文件以将您添加为合作者(因为终端未与您的 github 帐户同步,如果您在 win 或 mac 上使用 github 的 GUI 版本,实际上会发生这种情况)。

Other option is to fork his repo into your account, clone it from there to your PC and then send "pull request" to the original repo.

另一种选择是将他的 repo 分叉到您的帐户中,从那里将其克隆到您的 PC,然后向原始 repo 发送“拉取请求”。