Problem with GitHub template repository when I include all branches

I have a template repository on GitHub with 3 branches: master, develop and feature/auth and the reason for that is because the code of the branch feature/auth is optional depending on if the web application has authentication or not.

The problem I have is when I choose the option “Use this template” to generate new repositories and include all branches, then clone the new repository and merge feature/auth with develop an error shows up:

fatal: refusing to merge unrelated histories

I tried running git merge feature/auth --allow-unrelated-histories

But I got a lot of conflicts and I don’t want people who use the template to have to solve conflicts.

I don’t have this problem with the original repository, only with the template generated ones.

This are the steps to reproduce the issue:

  1. navigate to the template repository.
  2. click the option “Use this template”.
  3. fill the repository name field with any name you want and check the “Include all branches” checkbox, then click the “Create repository from template” button.
  4. after the new repository is generated, clone it to your computer.
  5. Enter the repository directory and run the following commands:
$ git fetch --all
$ git checkout feature/auth
$ git checkout develop
$ git merge feature/auth

I’ve asked in StackOverflow and some other forums but got no help at all. Can somebody please help me with this?

Thank you very much in advance.

Hi @juanmesa2097 :wave:

Thanks for coming into the community!
In order to save your future self and any other user that chooses to clone this repository the pain of fixing those conflicts, I recommend addressing those conflicts yourself and then push to your repository.

Hello @ernest-phillips, thanks for answering.

When you’re in the original repo no conflicts occur but when you use the original repo as a template and generate a new repository, then you got a lot of conflicts when you merge feature branches into develop branch.

1 Like

Hi @juanmesa2097 ,

In this case , a template repository may not be the best path here. We suggest using forks as they include the entire commit history of the parent repository, while a repository created from a template starts with a single commit.

Since a template leaves you with a single commit and no shared history, merges will be problematic.

I am having the same issue;
I am creating a repo on GitHub, just readme, git ignore and license.
From main I create a new branch, development;
From development I create a new branch, feature;
Make changes to feature, add commit, push to github;
Only feature have new code.
Turn into a template via settings.

I create a new repo and want to use as template including all branches.
Clone the repo, dot he job.
Add commit push.
Unrelated histories fatal error.
have all the branches but i can’t merge feature to development.
I was expecting a different flow;
With a template you want to replicate project including files and structures, branching including;
And in the newborn projects to operate as always.
add commit push merge
How to fix this in a clean way?
I mean, without solving conflicts not related to our work, and without using flag like --allow-unrelated-histories?