Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep a GitHub fork up to date without a merge commit or using CLI?

The normal GitHub flow to contribute to a repo is to create a fork of the upstream, clone a local copy where you make changes, then push back up to your fork and then create a PR to have your changes merged into upstream.

But if upstream changes after that, how do you update your fork without creating a merge commit (and also without using the git CLI)?

I already know how to do this in a way that will create a merge commit or which depend on the git command line interface. This question is specifically about using the GitHub.com website or GitHub Desktop application only (no CLI).

Since this is a very common workflow it seems like there should be some simple way to do it using the GitHub GUI.

To reiterate: any answers that use the CLI or create a merge commit (e.g. this way) will not be answering this question since I'm explicitly looking for a non-CLI solution.

like image 860
brentonstrine Avatar asked Jun 01 '19 18:06

brentonstrine


People also ask

How do I update my forked repository in GitHub?

On GitHub, navigate to the main page of the forked repository that you want to sync with the upstream repository. Select the Sync fork dropdown. Review the details about the commits from the upstream repository, then click Update branch.

Does forked repo automatically update?

Sync from the UI Clicking on that you have the possibility to compare the changes made in the source repo with the ones made in your forked repo, and also to automatically fetch and merge them into your repo.

How do you keep your fork in sync with an upstream repository?

Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.


1 Answers

without a merge commit or using CLI?

Not directly with GitHub web UI alone, since it would involve rebasing your PR branch on top of upstream/master

So in short: no.
But in less short... maybe, if you really want to try it.

Rebasing through GitHub web UI is actually possible, since Sept. 2016, ...

  • if you are the maintainer of the original repo, wanting to integrate a PR branch
  • if none of the replayed commit introduces a conflict

https://github.blog/wp-content/uploads/2016/09/a03fa9b6-7f35-11e6-8fa0-e16b2fede8ca.gif?resize=788%2C423

(This differs from GitHub Desktop, which, since June 5th 2019 does support rebasing. But that is a frontend to Git CLI, like other tools provide. For example GitKraken and interactive rebase)

So a convoluted workaround would be:

  • to fetch, then push upstream/master to the master branch of your own fork (a CLI operation, but more on that below)
  • change the base branch of your current PR to master (so a PR within the same repository: your own fork), provided you haven't pushed to master.
    Meaning: master in your fork represents the updated upstream/master, with upstream being the original repository that you have forked.
  • Since you are the owner of that repository (your fork), GitHub can then show you if you can rebase said branch to the base branch of the PR (master), but only if there is no conflict.
  • finally, change the base branch again, to <originalRepo>/master (which is the intended target of your PR)

The very first step is typically done through command line, but... there might be a trick to do it (update upstream master in your fork) through web UI: see "Quick Tip: Sync a Fork with the Original via GitHub’s Web UI" by Bruno Skvorc

In short, it involves:

  • creating a new branch from your current master (which would be at upstream/master at the time you forked the original repository)

https://help.github.com/assets/images/help/branch/branch-creation-text-box.png

  • Making a PR with that new branch and <originalRepo/master>
  • doing a base switch before creating the PR

https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/02/1454845571Screenshot-2016-02-07-12.41.28-1024x411.png

https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/02/1454964017Screenshot-2016-02-07-12.41.42.png

That is the step which artificially forces upstream/master to be refreshed

You can the create and merge it with the “Merge Pull Request” button (and “Confirm Merge” afterwards): the merge will be trivial: no merge commit.

The end result is: your own master branch (in your fork) updated with upstream/master (the master branch of the original repository)!

You can then resume the steps I describe above, and change the base of your current PR to your own (now refreshed) master branch, and see if you can rebase it!

like image 151
VonC Avatar answered Oct 15 '22 04:10

VonC