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

Sync current repo to another remote repo in Github Actions #177

Closed
kooyear opened this issue Mar 6, 2020 · 7 comments
Closed

Sync current repo to another remote repo in Github Actions #177

kooyear opened this issue Mar 6, 2020 · 7 comments
Labels
question Further information is requested

Comments

@kooyear
Copy link

kooyear commented Mar 6, 2020

Hi, currently I use the actions/checkout@v2 to implement the synchronization between two repos, the following is the Actions workflow file I used:
`
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Git-version
run: git version
- name: Git-remote-add
run: git remote add adobe https://github.com/kooyear/aem-sync-to.git
- name: Git-fetch-all
run: git fetch --all
- name: Git-checkout-adobe
run: git checkout -b sync-demo-master adobe/master
- name: Git-merge
run: git merge master
- name: Git-push
run: git push --set-upstream adobe master`

when this workflow is running, I got an error from

git merge master
error info is
Run git merge master fatal: refusing to merge unrelated histories ##[error]Process completed with exit code 128.

but when I run those commands in my local device, it works, the commands are
git clone https://github.com/kooyear/aem-sync-from aem-sync-from-m cd aem-sync-from-m git remote add adobe https://github.com/kooyear/aem-sync-to.git git fetch --all git checkout -b sync-demo-master adobe/master git merge master git push --set-upstream adobe master

Do you know what is the reason?

@ericsciple
Copy link
Contributor

actions/checkout@v2 is optimized to fetch a single commit by default. If you want to fetch all history for all branches, add git fetch --prune --unshallow

@ericsciple ericsciple added the question Further information is requested label Mar 6, 2020
@kooyear
Copy link
Author

kooyear commented Mar 6, 2020

@ericsciple Hi, thank you for your reply, I tried it, but still get the same error
image

@kooyear
Copy link
Author

kooyear commented Mar 6, 2020

@ericsciple , I also post my question in https://github.jparrowsec.cnmunity/t5/GitHub-Actions/Sync-git-repo-with-Github-Actions/m-p/49037/highlight/false#M7356 , might be more clear to describe to explain the problem I met

@ericsciple
Copy link
Contributor

Might need to git merge origin/master ?

@kooyear
Copy link
Author

kooyear commented Mar 7, 2020

@ericsciple still, I got the same error

Run git merge origin/master
fatal: refusing to merge unrelated histories
##[error]Process completed with exit code 128.

What I guess is the commands running in Github Actions environment are not as same as those running in my local device.

Can you help me to check if the outcome should be the same as commands below that I ran in my local device

git clone https://github.com/kooyear/aem-sync-from aem-sync-from-m 
cd aem-sync-from-m 
git remote add adobe https://github.com/kooyear/aem-sync-to.git 
git fetch --all 
git checkout -b sync-demo-master adobe/master 
git merge master 
git push --set-upstream adobe master

@ericsciple
Copy link
Contributor

If you are only running on push for master, I would expect this to work:

on:
  push:
    branches: [ master ]
job:
  asdf:
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.MY_TOKEN_WITH_PUSH_ACCESS_TO_THE_REMOTE }}
          fetch-depth: 0
      - run: |
          git remote add adobe https://github.com/kooyear/aem-sync-to.git
          git push --set-upstream adobe master

I dont think you want to run on the pull_request event trigger.

@DanielLDorn
Copy link

DanielLDorn commented Mar 27, 2020

I had a similar problem and had to use git fetch --prune --unshallow per @ericsciple's suggestion along with a forced push:

-run
git fetch --prune --unshallow
git remote add remote_alias [ssh url_to_remote]
git push -f remote_alias master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants