How to keep my forked repo updated with the original repo

I forked a public repo, changed a line of code (set a new value for a constant to be specific). I want my forked repo to be updated with the original repo, means that everytime the original repo has a new commit on master branch, my forked repo will get updated automatically so both master branchs are always the same. Can I do that and how ?

Bonus question if there is the way: Can I automatically cherry pick the commit that changes the constant as well ?

There’s no built-in automation that I know of, but you could probably set up a Github Actions workflow to do that for you. I’m thinking of something like the following:

  • Run the workflow on a schedule.
  • After checking out your repository, add the upstream repository as a remote and fetch.
  • Check if the upstream branch has new commits. If yes, rebase or merge your code (depending on what you want) and push to your repository.

Ideally run tests before pushing so you don’t accidentally get any broken code. :wink:

1 Like

Hey! @airtower-luna @tannguyen

Is there any update on how this possibility is being developed? I am not at all familiar with GitHub Actions, but surely there is some kind of script for this to work. Even if there was, it could cause the fork to not be perfectly aligned with its origin. Anyways, if this seems like something that will not be developed by GitHub, I believe this could be done with a shell script via GitHub CLI.

Along with this, I believe it may be handy if we had some sort of fork reset button: basically deleting the branch and re-forking it, which could also be possible with gh.

I don’t work for Github, so I couldn’t say what’s being developed internally. :wink:

There is the Repo Sync set of actions that were developed for Open Source work on Github docs, maybe they would be useful for you? The tricky thing with an Actions-based is that scheduled actions must be on the default branch, so you can’t hard-reset that to the upstream version or your scheduled workflow will be gone.

1 Like

I gave the organization a look, and although it is great that they have a project where you can sync two repos, the main issue they have is needing both to have the GitHub Actions script.

Install GitHub Desktop. There, you can fetch the changes made (whenever there are changes while you are editing your forked repo) in the original repo and add your own.

Here is the complete answer:

1 Like