Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync fork #27

Open
hudapaba opened this issue Jun 6, 2015 · 2 comments
Open

Sync fork #27

hudapaba opened this issue Jun 6, 2015 · 2 comments

Comments

@hudapaba
Copy link
Contributor

hudapaba commented Jun 6, 2015

Luke, How do we make sure our forks stay in sync with your master?

@truthsword
Copy link
Contributor

Yes... this is confusing. Books that were added to the master after I forked, do not appear in my fork, Nor do the changes that others have made. Hopefully we are not working on the same texts, haha.

If I were to re-sync the master with my fork, all the pending commits in my fork would be overwritten, so I dare not do that. I'm wondering if GitHub is the best place for this?

@ricompute
Copy link

Okay, so I'm still relatively new to Git, but here's my tentative answer to this issue.

The short answer is that, as long as you are careful, I don't think re-syncing with the original repository will overwrite your pending commits. I think Git is smart enough to merge in changes others have made without getting rid of the changes you have made, especially if you have been working on different files. If you happen to have been working on the same part of the same file, Git will create conflict messages that you will have to resolve, but it shouldn't automatically overwrite anyone's changes. (That being said, it might be worth having some kind of signup page, perhaps on the main repository's GitHub wiki, where people can let everyone know which books are currently being worked on and avoid creating conflicts.)

The long answer is that I don't think GitHub's GUI software is advanced enough to let you sync your fork with the original repository, so you will have to do a few things from the command line. Before I continue, let me offer this disclaimer: I haven't actually tried the following steps, so take everything with a grain of salt. It would be great if someone with more experience with Git could make sure this is actually the right thing to do. That being said, I'm basically just taking this from GitHub's help pages, so as far as I can tell it should work. Okay, here we go:

  1. From the GitHub GUI application, first make sure your local repository is synced with your online repository (press the "Sync" button). Next, right-click on the repository (in the list of repositories on the left). Then, click "Open in Git Shell." This should open a command line window in the correct directory.

  2. Configuring a remote for a fork. You need to add the original repository to your fork as a "remote" that Git can check for changes.

    1. List the current configured remote repository for your fork by typing the following:

      git remote -v
      

      You should see something like this:

      origin  https://github.com/YOURUSERNAME/books.git (fetch)
      origin  https://github.com/YOURUSERNAME/books.git (push)
      
    2. Add the original repository as a remote called upstream by typing:

      git remote add upstream https://github.com/deeproots/books.git
      
    3. Make sure it worked by again typing:

      git remote -v
      

      You should now see:

      origin  https://github.com/YOURUSERNAME/books.git (fetch)
      origin  https://github.com/YOURUSERNAME/books.git (push)
      upstream  https://github.com/deeproots/books.git (fetch)
      upstream  https://github.com/deeproots/books.git (push)
      
  3. Now, fetch changes from the original repository. See Syncing a fork.

    git fetch upstream
    

    You should see something like this:

    remote: Counting objects: 75, done.
    remote: Compressing objects: 100% (53/53), done.
    remote: Total 62 (delta 27), reused 44 (delta 9)
    Unpacking objects: 100% (62/62), done.
    From https://github.com/deeproots/books.git
     * [new branch]      master     -> upstream/master
    
  4. Checkout your fork's local master branch:

    git checkout master
    
  5. Merge changes from the original repository into your local fork:

    git merge upstream/master
    

    If you have pending commits, this should not ovwrite them. You should something like this:

    Updating a422352..5fdff0f
    Fast-forward
     FILENAME                    |    9 -------
     FILENAME.md                 |    7 ++++++
     2 files changed, 7 insertions(+), 9 deletions(-)
     delete mode 100644 FILENAME
     create mode 100644 FILENAME.md
    

    If you don't have any pending commits, you should see something like this:

    Updating 34e91da..16c56ad
    Fast-forward
     FILENAME.md                 |    5 +++--
     1 file changed, 3 insertions(+), 2 deletions(-)
    
  6. Now, make sure your local fork is in sync with your online GitHub repository.

    git push origin
    

If you do end up with conflicts, you can see how to resolve them here.

So, those are my two cents. I hope it was helpful. I don't think anyone will loose any work, but like I said, I haven't actually tried any of this. It might be a good idea to make a backup of your changed files first, just in case. (Or, try creating a new branch of your fork to try syncing/merging with first. But that's its own can of worms.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants