Merge changes from GitHub template repository

It’s very convenient to use GitHub template repository feature to bootstrap a repository. I thought it would also have functionality like Syncing a fork , but unfortunately it doesn’t.

So to sync changes from upstream template repository, we need to use git command line:

  1. Add remote

    git remote add template <repo>
    
  2. Fetch template changes

    git fetch --all
    
  3. Use --allow-unrelated-histories to merge, we may also need to manually resolve all the merge conflicts.

    git merge --allow-unrelated-histories --squash template/<branch>
    

--allow-unrelated-histories: By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.

There is also GitHub action actions-template-sync which can be configured to automatically sync changes from template.

References