20

I am currently using the Windows Github GUI and its pretty cool looking and easy so I'm trying to use it as often. A problem I encountered is when I fork a project I don't know how to update that fork with the git

Postscripter
  • 521
  • 7
  • 18
TakaGoto
  • 362
  • 4
  • 17

4 Answers4

30

And just for reference I copy here the detailed instructions from a post at http://processwire.com/talk/topic/1565-github-for-windows/:

  • In "GitHub for Windows" local repositories view, right-click and choose "open a shell here"
  • This will open a shell already in the right directory. Type the following commands:
# Assigns the original repo to a remote called "upstream"
git remote add upstream https://github.com/path_to_your_repository.git 

# Pulls in changes from the original repo not present in your local repository, 
# without modifying your files. 
# Allows you to review first.
git fetch upstream 

# merge fetched changes into your working files.
git merge upstream/master 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Gustav Delius
  • 1,933
  • 1
  • 16
  • 10
  • Nice concrete addition to my answer. +1 – VonC Apr 11 '13 at 09:07
  • @VonC: Thanks for fixing the formatting for me. I learned from it. Also, I had at first tried to add a comment to your answer instead of posting a new answer but the allowed length of comments was not sufficient. – Gustav Delius Apr 15 '13 at 09:37
  • Also take a look at http://www.jonathanmedd.net/2013/06/git-remote-add-upstream-fatal-remote-upstream-already-exists.html if you are getting "fatal 'upstream' does not appear to be a git repository" error – mosesfetters Jul 02 '13 at 19:08
17

GitHub for Windows only supports one remote for now (origin, which reference your fork).

So you need to manually add a remote (called 'upstream') referencing the original repo, in order for you to be able to pull (from the CLI) from upstream, updating your local repo and allowing you to push (this time with the GUI) the new commits to your fork.

See "What is the difference between origin and upstream in github" for more.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Syncing a fork

Sync a fork of a repository to keep it up-to-date with the upstream repository.

Tip: Before you can sync your fork with an upstream repository, you must configure a remote that points to the upstream repository in Git.

1. Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).

2. Change the current working directory to your local project.

3. Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master.

$ git fetch upstream


4. Check out your fork's local master branch.

$ git checkout master


5. Merge the changes from upstream/master into your local master branch. This brings your fork's master branch into sync with the upstream repository, without losing your local changes.

$ git merge upstream/master

If your local branch didn't have any unique commits, Git will instead perform a "fast-forward":

$ git merge upstream/master

Tip: Syncing your fork only updates your local copy of the repository. To update your fork on GitHub, you must push your changes.


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

enter image description here

In Github for Windows (GUI application), press button Sync, then application will upload changed files to your own repository (at Github.com). enter image description here

Vy Do
  • 46,709
  • 59
  • 215
  • 313
2

How to sync a fork repository from an original repository?

For easy understand, I call an reality example: Sync this repository: https://github.com/donhuvy/scrapy from https://github.com/scrapy/scrapy

There’re all steps:

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$ 

enter image description here

Important points:

Step 1. Change directory:

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

To be sure:

pwd

Step 2. Go to https://github.com/donhuvy/scrapy look at the top right, copy repository link

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

Step 3. Clone from server to local

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

Step 4. Go to https://github.com/scrapy/scrapy , look at the top right, copy repository link

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

Step 5. Add upstream repository link

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

Step 6. Check repo list: git remote -v

Result:

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)

Step 7. Fetch upstream

git fetch upstream

Step 8. Get master branch from upstream repo

git checkout master

Step 9. Merge source code:

git merge upstream/master

Vim editor open inside terminal, then you edit commit message, press i for starting edit, press esc, :wq! for quit and save.

Step 10. Make a commit

git commit -m "update"

Step 11. Push git push

Step 12. To be sure

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.

Reference:

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

Vy Do
  • 46,709
  • 59
  • 215
  • 313