Checkout: fatal: refusing to merge unrelated histories

Created on 26 Dec 2019  路  3Comments  路  Source: actions/checkout

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.

Most helpful comment

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.

All 3 comments

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.

Thanks, that makes sense!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitfool picture gitfool  路  3Comments

KOLANICH picture KOLANICH  路  4Comments

chorrell picture chorrell  路  4Comments

rster2002 picture rster2002  路  7Comments

aaronsteers picture aaronsteers  路  3Comments