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

fatal: refusing to merge unrelated histories #125

Closed
pdcmoreira opened this issue Dec 26, 2019 · 4 comments · Fixed by #127
Closed

fatal: refusing to merge unrelated histories #125

pdcmoreira opened this issue Dec 26, 2019 · 4 comments · Fixed by #127

Comments

@pdcmoreira
Copy link

pdcmoreira commented Dec 26, 2019

I'm getting the fatal: refusing to merge unrelated histories when I'm trying to merge branches, for some reason.

My steps:

- name: Use checkout v2
  uses: actions/checkout@v2
  with:
    ref: refs/heads/master
    token: ${{ secrets.GITHUB_CI_TOKEN }}
- name: Merge development into master
  run: |
    echo "# Config"
    git config --local user.email "[hidden]"
    git config --local user.name "CI"
    echo "# Fetch all"
    git fetch --all
    echo "# Checkout/pull development"
    git checkout development
    git pull
    echo "# Checkout/pull master"
    git checkout master
    git pull
    echo "# Merge"
    git merge development -X theirs
    echo "# Push"
    git push origin master

The error:
image

master and development branches can't have unrelated histories, because development was branched from master.

Running those commands locally works as expected.

Update:
Adding --allow-unrelated-histories to the merge command makes it work.
I don't understand how does git detect the branches as having different histories though.

@ericsciple
Copy link
Contributor

V2 sets the detch depth to 1 by default. You might need to either set fetch-depth: 0 or add the flag --unshallow to the fetch command.

@pdcmoreira
Copy link
Author

Thanks, that makes sense!

@ericsciple
Copy link
Contributor

@pdcmoreira thanks for confirmation. I'm updating the docs to make this more clear.

@fabienthetis
Copy link

V2 sets the detch depth to 1 by default. You might need to either set fetch-depth: 0 or add the flag --unshallow to the fetch command.

You saved my day

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

Successfully merging a pull request may close this issue.

3 participants