【问题标题】:update fork on GitHub for Windows?在 GitHub 上更新 fork for Windows?
【发布时间】:2012-11-04 18:16:56
【问题描述】:

我目前正在使用 Windows Github GUI,它的外观非常酷且简单,因此我尝试经常使用它。我遇到的一个问题是,当我 fork 一个项目时,我不知道如何使用 git 更新该 fork

【问题讨论】:

    标签: github


    【解决方案1】:

    GitHub for Windows 目前只支持一个遥控器(origin,它引用了你的 fork)。

    因此,您需要手动添加引用原始存储库的远程(称为“upstream”),以便您能够(从 CLI)从 upstream 拉取,更新您的本地存储库并允许您推送(这次使用 GUI)新的提交到你的 fork。

    请参阅“What is the difference between origin and upstream in github”了解更多信息。

    【讨论】:

      【解决方案2】:

      仅供参考,我在此处复制http://processwire.com/talk/topic/1565-github-for-windows/ 的帖子中的详细说明:

      • 在“GitHub for Windows”本地存储库视图中,右键单击并选择“open a shell here
      • 这将打开一个已经在正确目录中的 shell。输入以下命令:
      # 将原始 repo 分配给名为“upstream”的远程 git 远程添加上游 https://github.com/path_to_your_repository.git # 从原始存储库中提取本地存储库中不存在的更改, # 不修改你的文件。 # 允许您先查看。 git 获取上游 # 将获取的更改合并到您的工作文件中。 git 合并上游/主

      【讨论】:

      • 我的回答很好的具体补充。 +1
      • @VonC:感谢您为我修复格式。我从中吸取了教训。另外,我最初尝试在您的答案中添加评论而不是发布新答案,但允许的 cmets 长度不够。
      • 如果您收到“致命的‘上游’似乎不是 git 存储库”错误,请查看 jonathanmedd.net/2013/06/…
      【解决方案3】:

      同步分叉

      同步存储库的一个分支,以使其与上游保持同步 存储库。

      提示:在您将 fork 与上游存储库同步之前,您 在 Git 中必须 configure a remote that points to the upstream repository

      1. 打开终端(Mac 用户)或命令提示符(Windows 和 Linux 用户)。

      2. 将当前工作目录更改为您的本地项目。

      3. 从上游存储库中获取分支及其各自的提交。对master 的提交将存储在本地 分支,upstream/master.

      $ git fetch upstream
      


      4. 查看你的 fork 的本地 master 分支。

      $ git checkout master
      


      5. 将来自upstream/master 的更改合并到您本地的master 分支。这会使你的 fork 的 master 分支同步 使用上游存储库,而不会丢失您的本地更改。

      $ git merge upstream/master
      

      如果您的本地分支没有任何独特的提交,Git 将改为 执行“快进”:

      $ git merge upstream/master
      

      提示:同步您的分叉只会更新您的本地存储库副本。 要在 GitHub 上更新您的分叉,您必须推送您的更改。


      来源: https://help.github.com/articles/syncing-a-fork/

      在 Windows 版 Github(GUI 应用程序)中,按下按钮 Sync,然后应用程序会将更改的文件上传到您自己的存储库(在 Github.com)。

      【讨论】:

        【解决方案4】:

        如何从原始存储库同步复刻存储库?

        为了便于理解,我举个实际例子:Sync this repository: https://github.com/donhuvy/scrapy from https://github.com/scrapy/scrapy

        所有步骤:

        Last login: Fri Sep  2 08:45:34 on ttys000
        Dos-MacBook-Pro:~ donhuvy$ 
        Dos-MacBook-Pro:~ donhuvy$ 
        Dos-MacBook-Pro:~ donhuvy$ ls
        AndroidStudioProjects   IdeaProjects        Public
        Applications        Library         PycharmProjects
        Desktop         Movies          example.dump
        Documents       Music           pgadmin.log
        Downloads       Pictures        sun-appserv-samples
        Dos-MacBook-Pro:~ donhuvy$ cd Documents/
        Dos-MacBook-Pro:Documents donhuvy$ ls
        $RECYCLE.BIN
        13256069_130212657393823_216708148326317354_n.jpg
        1511456_1453604554870601_599093550_n.jpg
        4578-rc007-jquery_online.pdf
        Apps
        Programming ebooks
        Setup
        Treasure_Island_NT.pdf
        Video tutorial
        Virtual Machines.localized
        films
        postgresql-9.0-A4.pdf
        program_files
        source_code
        vy.sql
        workspace_javaee
        Dos-MacBook-Pro:Documents donhuvy$ cd source_code/
        Dos-MacBook-Pro:source_code donhuvy$ ls
        github.com
        Dos-MacBook-Pro:source_code donhuvy$ cd github.com/
        Dos-MacBook-Pro:github.com donhuvy$ ls
        AurelioDeRosa   donhuvy     hibernate-orm   scrapy      spring-projects
        Dos-MacBook-Pro:github.com donhuvy$ cd donhuvy/
        Dos-MacBook-Pro:donhuvy donhuvy$ ls
        ZohoCRM_integration jquery3_examples
        java_examples       real_estate
        Dos-MacBook-Pro:donhuvy donhuvy$ git clone https://github.com/donhuvy/scrapy.git
        Cloning into 'scrapy'...
        remote: Counting objects: 40481, done.
        remote: Total 40481 (delta 0), reused 0 (delta 0), pack-reused 40481
        Receiving objects: 100% (40481/40481), 13.98 MiB | 746.00 KiB/s, done.
        Resolving deltas: 100% (21135/21135), done.
        Checking connectivity... done.
        Dos-MacBook-Pro:donhuvy donhuvy$ '
        > 
        > 
        > 
        Dos-MacBook-Pro:donhuvy donhuvy$ 
        Dos-MacBook-Pro:donhuvy donhuvy$ 
        Dos-MacBook-Pro:donhuvy donhuvy$ ls
        ZohoCRM_integration jquery3_examples    scrapy
        java_examples       real_estate
        Dos-MacBook-Pro:donhuvy donhuvy$ cd sc
        -bash: cd: sc: No such file or directory
        Dos-MacBook-Pro:donhuvy donhuvy$ cd scrapy/
        Dos-MacBook-Pro:scrapy donhuvy$ ls
        AUTHORS         README.rst      requirements.txt
        CODE_OF_CONDUCT.md  artwork         scrapy
        CONTRIBUTING.md     conftest.py     sep
        INSTALL         debian          setup.cfg
        LICENSE         docs            setup.py
        MANIFEST.in     extras          tests
        Makefile.buildbot   pytest.ini      tox.ini
        NEWS            requirements-py3.txt
        Dos-MacBook-Pro:scrapy donhuvy$ git log
        commit ab42e2b5d531cbbf2ee46b49726604c90becbd3d
        Author: vydn <v@vyhn.net>
        Date:   Sat Apr 2 06:08:28 2016 +0700
        
            Change the content
        
            Change the content
        
        commit bf7f67549378269c3976afc89abcf9c2190d242f
        Merge: 9d8c368 9250a5b
        Author: Paul Tremberth <paul.tremberth@gmail.com>
        Date:   Fri Apr 1 15:47:06 2016 +0200
        
            Merge pull request #1847 from aron-bordin/add_blocking_storage_path_setting
        
            [MRG+2] added BLOCKING_FEED_STORAGE_PATH to settings
        
        commit 9250a5bffa91c24dbea5c5d64c3c7cd9992a6ee7
        Author: Aron Bordin <aron.bordin@gmail.com>
        Date:   Sat Mar 5 19:36:02 2016 -0300
        
            added FEED_TEMPDIR to settings
        
        commit 9d8c368ce8a24d7adb63b731df1359f3b05f3bdd
        Dos-MacBook-Pro:scrapy donhuvy$ 
        Dos-MacBook-Pro:scrapy donhuvy$ 
        Dos-MacBook-Pro:scrapy donhuvy$ git fetch upstream
        fatal: 'upstream' does not appear to be a git repository
        fatal: Could not read from remote repository.
        
        Please make sure you have the correct access rights
        and the repository exists.
        Dos-MacBook-Pro:scrapy donhuvy$ git remote -v
        origin  https://github.com/donhuvy/scrapy.git (fetch)
        origin  https://github.com/donhuvy/scrapy.git (push)
        Dos-MacBook-Pro:scrapy donhuvy$ git remote add upstream https://github.com/scrapy/scrapy.git
        Dos-MacBook-Pro:scrapy donhuvy$ git remote -v
        origin  https://github.com/donhuvy/scrapy.git (fetch)
        origin  https://github.com/donhuvy/scrapy.git (push)
        upstream    https://github.com/scrapy/scrapy.git (fetch)
        upstream    https://github.com/scrapy/scrapy.git (push)
        Dos-MacBook-Pro:scrapy donhuvy$ git fetch upstream
        remote: Counting objects: 1329, done.
        remote: Compressing objects: 100% (7/7), done.
        remote: Total 1329 (delta 600), reused 599 (delta 599), pack-reused 723
        Receiving objects: 100% (1329/1329), 425.28 KiB | 325.00 KiB/s, done.
        Resolving deltas: 100% (920/920), completed with 141 local objects.
        From https://github.com/scrapy/scrapy
         * [new branch]      0.12       -> upstream/0.12
         * [new branch]      0.14       -> upstream/0.14
         * [new branch]      0.16       -> upstream/0.16
         * [new branch]      0.18       -> upstream/0.18
         * [new branch]      0.20       -> upstream/0.20
         * [new branch]      0.22       -> upstream/0.22
         * [new branch]      0.24       -> upstream/0.24
         * [new branch]      1.0        -> upstream/1.0
         * [new branch]      1.1        -> upstream/1.1
         * [new branch]      asyncio    -> upstream/asyncio
         * [new branch]      deprecate-make-requests-from-url -> upstream/deprecate-make-requests-from-url
         * [new branch]      disable-toplevel-2 -> upstream/disable-toplevel-2
         * [new branch]      doc-arch-overview2 -> upstream/doc-arch-overview2
         * [new branch]      feature-1371-download-prios -> upstream/feature-1371-download-prios
         * [new branch]      fix-1330   -> upstream/fix-1330
         * [new branch]      fix-util-function-to-work-outside-project-dir -> upstream/fix-util-function-to-work-outside-project-dir
         * [new branch]      link-encoding -> upstream/link-encoding
         * [new branch]      master     -> upstream/master
         * [new branch]      no-max-rss -> upstream/no-max-rss
         * [new branch]      py3-chunked -> upstream/py3-chunked
         * [new branch]      release-notes-1.1.2-master -> upstream/release-notes-1.1.2-master
         * [new branch]      remove-prerelease-configuration -> upstream/remove-prerelease-configuration
         * [new tag]         1.0.6      -> 1.0.6
         * [new tag]         1.1.2      -> 1.1.2
         * [new tag]         1.1.0      -> 1.1.0
         * [new tag]         1.1.0rc4   -> 1.1.0rc4
         * [new tag]         1.1.1      -> 1.1.1
        Dos-MacBook-Pro:scrapy donhuvy$ git checkout master
        Already on 'master'
        Your branch is up-to-date with 'origin/master'.
        Dos-MacBook-Pro:scrapy donhuvy$ git merge upstream/master
        error: There was a problem with the editor 'vi'.
        Not committing merge; use 'git commit' to complete the merge.
        Dos-MacBook-Pro:scrapy donhuvy$ git commit -m "update"
        [master 6f16b46] update
        Dos-MacBook-Pro:scrapy donhuvy$ git push
        Counting objects: 915, done.
        Delta compression using up to 8 threads.
        Compressing objects: 100% (380/380), done.
        Writing objects: 100% (915/915), 235.84 KiB | 0 bytes/s, done.
        Total 915 (delta 677), reused 769 (delta 535)
        remote: Resolving deltas: 100% (677/677), completed with 99 local objects.
        To https://github.com/donhuvy/scrapy.git
           ab42e2b..6f16b46  master -> master
        Dos-MacBook-Pro:scrapy donhuvy$ git status
        On branch master
        Your branch is up-to-date with 'origin/master'.
        nothing to commit, working tree clean
        Dos-MacBook-Pro:scrapy donhuvy$ 
        

        要点:

        第 1 步。 更改目录:

        cd /Users/donhuvy/Documents/source_code/github.com/donhuvy/
        

        确定:

        pwd
        

        第2步。转到https://github.com/donhuvy/scrapy查看右上角,复制存储库链接

        https://github.com/donhuvy/scrapy.git
        

        第 3 步。 从服务器克隆到本地

        git clone https://github.com/donhuvy/scrapy.git
        

        第4步。转到https://github.com/scrapy/scrapy,查看右上角,复制存储库链接

        https://github.com/scrapy/scrapy.git
        

        第 5 步。 添加上游存储库链接

        git remote add upstream https://github.com/scrapy/scrapy.git
        

        第 6 步。 检查 repo 列表: git远程-v

        结果:

        来源https://github.com/donhuvy/scrapy.git(获取) 原点https://github.com/donhuvy/scrapy.git(推) 上游https://github.com/scrapy/scrapy.git(获取) 上游https://github.com/scrapy/scrapy.git(推送)

        第 7 步。 获取上游

        git fetch upstream
        

        第 8 步。 从上游仓库获取主分支

        git checkout master
        

        第 9 步。 合并源代码:

        git merge upstream/master
        

        Vim 编辑器在终端打开,然后编辑提交信息,按 i 开始编辑,按 esc:wq! 退出并保存。

        第 10 步。 提交

        git commit -m "update"
        

        第 11 步。 推送 git 推送

        第 12 步。 确定

        git status
        
        On branch master
        Your branch is up-to-date with 'origin/master'.
        nothing to commit, working tree clean
        Of course, I try to my post have no 13rd step.
        

        参考:

        https://help.github.com/articles/configuring-a-remote-for-a-fork/ https://help.github.com/articles/syncing-a-fork/

        【讨论】:

        • 有趣的教程。 +1
        猜你喜欢
        • 2015-09-14
        • 2012-12-15
        • 2012-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多