克隆来自其他人的Github的回购并将其推送到我的Github上的回购

jac*_*n09 64 git github

我在https://github.com/railstutorial/sample_app_rails_4克隆了回购并对它进行了很多更改(我用它作为我自己的应用程序的起点),现在我想将更改的应用程序推送到回复我自己的github帐户.

如何更改链接到的github repo?

mga*_*aia 96

正如Deefour所说,您的情况与更改远程Git存储库的URI(URL)的情况并无太大差别.当您clone成为存储库时,它将remote以名称的形式添加为您的存储库origin.您现在需要做的是(因为您不再使用旧源)是更改origin的URL:

$ git remote set-url origin http://github.com/YOU/YOUR_REPO
Run Code Online (Sandbox Code Playgroud)

如果原始存储库经常更新并且您希望不时地获取这些更新,那么origin最好添加一个新的remote:

$ git remote add personal http://github.com/YOU/YOUR_REPO
Run Code Online (Sandbox Code Playgroud)

或者甚至可以打电话给旧的upstream:

$ git remote rename origin upstream
$ git remote add origin http://github.com/YOU/YOUR_REPO
Run Code Online (Sandbox Code Playgroud)

然后,只要您想要进行更改upstream,您就可以:

$ git fetch upstream
Run Code Online (Sandbox Code Playgroud)

因为这个源是一个示例存储库(似乎是一种开始的模板),我认为不需要保留它或根本不需要它 - 我会选择第一个替代方案.


Der*_*ike 43

GitHub:git clone别人的存储库和git push你自己的存储库

我将把别人的存储库称为另一个存储库.


  1. github.com上创建一个新的存储库.(这是你的存储库)

    • 为它指定与其他存储库相同的名称.
    • 不要使用README,.gitignore或许可证对其进行初始化.
  2. 其他存储库克隆到本地计算机.(如果你还没有这样做过)

    • git clone https://github.com/other-account/other-repository.git
  3. 将本地存储库的当前" origin " 重命名为" upstream ".

    • git remote rename origin upstream
  4. 给本地资源库的" 原产地 "指向你的资料库.

    • git remote add origin https://github.com/your-account/your-repository.git
  5. 将本地存储库推送到github 上的存储库.

    • git push origin master

现在,' origin '指向您的存储库,' upstream '指向另一个存储库.

  • 使用,为您的更改创建一个新分支git checkout -b my-feature-branch.
  • 您可以git commit照常使用您的存储库.
  • 使用git pull upstream master拉从改变其他仓库到你的主分支.

  • 很好解释+1 (2认同)
  • 很好的解释,但是当尝试“git push origin master”时,我得到:“...压缩对象:100%(1093/1093),完成。写入对象:100% (4185/4185),504.89 KiB | 126.22 MiB/s,完成。总计 4185(增量 3049),重用 4185(增量 3049)远程:解决增量:100%(3049/3049),完成。远程: pre-receive.sh:执行超过 5 秒超时 到 https://github.com/your-account/your-repository.git ![远程拒绝] master -> master(预接收挂钩被拒绝)错误:无法将一些引用推送到'https://github.com/your-account/your-repository.git'` (2认同)

小智 9

删除git并重新初始化.

你的目的可能是把这个回购放在你的上面并把它变成你的.

想法是删除.git/并重新初始化.

  1. 转到克隆的repo文件夹 rm -rf .git
  2. 重新初始化它然后添加你的遥控器并进行第一次推送.
    git init
    git add .
    git commit -m "your commit message"
    git remote add origin 
    git push origin master
    


小智 8

您可以通过从本地存储库创建新远程(通过命令行)来完成此操作.

git remote add <name> <url>
Run Code Online (Sandbox Code Playgroud)

然后你可以打电话:

git push <name> <repo_name>
Run Code Online (Sandbox Code Playgroud)

要替换已设置的默认"origin"远程,您可以运行以下命令:

git remote rm origin
git remote add origin <url>
Run Code Online (Sandbox Code Playgroud)


lle*_*ekn 7

我认为这样做的"最礼貌的方式"是:

  1. 在您的GitHub帐户上分叉原始仓库
  2. 检查一个新的分支以进行更改git checkout -b <your_branch_name>(如果您之前没有这样做)
  3. 为本地存储库添加新远程: git remote add github <your_repository_ssh_url>
  4. 将您漂亮的新分支推送到您的github存储库: git push github <your_branch_name>

通过这种方式,您将拥有一个分支到原始仓库的仓库,您的更改将在一个单独的分支中提交.如果您想向原始仓库提交拉取请求,这种方式会更容易.