I have a checkout/v3 action that pulls from a remote repository
- uses: actions/checkout@v3
with:
repository: myorg/myrepo
ref: mybranch
token: ${{ secrets.ACCESS_TOKEN }}
And then trying to merge in a remote branch
- run: |
git config --global user.email "[email protected]"
git config --global user.name "me"
git fetch
git merge mybranch origin/${{ env.ANOTHER_BRANCH}}
The first issue I am having is that this fails with an unexpected error
fatal: refusing to merge unrelated histories
These are both branches off of main, with only 1 single letter change test commit made to ANOTHER_BRANCH.
Adding the setting --allow-unrelated-histories takes me past that error, but then I get a merge conflict.
The trouble is this is the only place I get the conflict, so I can't resolve it. If I create a pull request between from ANOTHER_BRANCH -> mybranch there are no reported conflicts. If I pull these branches down locally and do the same merge, there is no conflict. Seems the conflict is related to my GH Action use case.
Any ideas?
CodePudding user response:
GitHub actions use shallow clones by default, as an optimization: there's no point in fetching the whole history if you're not going to use it!
In your use case, however, you are using the history, so you can ask for it with fetch-depth: 0
. That will fetch the full history.
Solution, found in a different question with the same fix:
- uses: actions/checkout@v3
with:
fetch-depth: 0
Ref: https://stackoverflow.com/a/71819349/3216427
CodePudding user response:
These are both branches off of main
Make sure with git branch -a --contains main
.