2
git fetch upstream
git checkout main
git rebase upstream/main
git push -f origin main

These when run locally from cmd/bash, work flawlessly by updating my commits to the top of synced updates.
When I try to do the same with GitHub Actions just for sake of automation, why does it throw conflicts?

Auto-merging app/build.gradle
CONFLICT (add/add): Merge conflict in app/build.gradle
Auto-merging app/src/main/AndroidManifest.xml
CONFLICT (add/add): Merge conflict in app/src/main/AndroidManifest.xml
Auto-merging app/src/main/java/androidx/documentfile/provider/DocumentFileHelper.java
CONFLICT (add/add): Merge conflict in app/src/main/java/androidx/documentfile/provider/DocumentFileHelper.java
...
Auto-merging app/src/main/res/layout/about_preset_item.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/about_preset_item.xml
Auto-merging app/src/main/res/layout/conversation_list_fragment.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/conversation_list_fragment.xml
Auto-merging app/src/main/res/layout/dsl_payments_preference.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/dsl_payments_preference.xml
Auto-merging app/src/main/res/layout/edit_about_fragment.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/edit_about_fragment.xml
Auto-merging app/src/main/res/layout/edit_proxy_fragment.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/edit_proxy_fragment.xml
Auto-merging app/src/main/res/layout/fragment_edit_notification_profile.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/fragment_edit_notification_profile.xml
Auto-merging app/src/main/res/layout/main_activity_list_host_fragment.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/main_activity_list_host_fragment.xml
Auto-merging app/src/main/res/layout/manage_profile_fragment.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/manage_profile_fragment.xml
Auto-merging app/src/main/res/layout/my_support_preference.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/my_support_preference.xml
Auto-merging app/src/main/res/layout/on_reaction_sent_view.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/on_reaction_sent_view.xml
Auto-merging app/src/main/res/layout/share_button.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/share_button.xml
Auto-merging app/src/main/res/layout/signal_bottom_action_bar_item.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/signal_bottom_action_bar_item.xml
Auto-merging app/src/main/res/layout/signal_context_menu_item.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/signal_context_menu_item.xml
Auto-merging app/src/main/res/layout/sticker_management_sticker_item.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/sticker_management_sticker_item.xml
Auto-merging app/src/main/res/layout/stories_landing_item.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/stories_landing_item.xml
Auto-merging app/src/main/res/layout/stories_landing_item_my_stories.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/stories_landing_item_my_stories.xml
Auto-merging app/src/main/res/layout/stories_viewer_fragment_page.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/stories_viewer_fragment_page.xml
Auto-merging app/src/main/res/layout/tooltip.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/layout/tooltip.xml
Auto-merging app/src/main/res/navigation/sms_export.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/navigation/sms_export.xml
Auto-merging app/src/main/res/values-af/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-af/strings.xml
Auto-merging app/src/main/res/values-ar/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ar/strings.xml
Auto-merging app/src/main/res/values-az/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-az/strings.xml
Auto-merging app/src/main/res/values-bg/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-bg/strings.xml
Auto-merging app/src/main/res/values-bn/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-bn/strings.xml
Auto-merging app/src/main/res/values-bs/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-bs/strings.xml
Auto-merging app/src/main/res/values-ca/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ca/strings.xml
Auto-merging app/src/main/res/values-cs/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-cs/strings.xml
Auto-merging app/src/main/res/values-da/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-da/strings.xml
Auto-merging app/src/main/res/values-de/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-de/strings.xml
Auto-merging app/src/main/res/values-el/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-el/strings.xml
Auto-merging app/src/main/res/values-es/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-es/strings.xml
Auto-merging app/src/main/res/values-et/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-et/strings.xml
Auto-merging app/src/main/res/values-eu/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-eu/strings.xml
Auto-merging app/src/main/res/values-fa/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-fa/strings.xml
Auto-merging app/src/main/res/values-fi/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-fi/strings.xml
Auto-merging app/src/main/res/values-fr/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-fr/strings.xml
Auto-merging app/src/main/res/values-ga/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ga/strings.xml
Auto-merging app/src/main/res/values-gl/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-gl/strings.xml
Auto-merging app/src/main/res/values-gu/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-gu/strings.xml
Auto-merging app/src/main/res/values-hi/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-hi/strings.xml
Auto-merging app/src/main/res/values-hr/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-hr/strings.xml
Auto-merging app/src/main/res/values-hu/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-hu/strings.xml
Auto-merging app/src/main/res/values-in/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-in/strings.xml
Auto-merging app/src/main/res/values-it/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-it/strings.xml
Auto-merging app/src/main/res/values-iw/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-iw/strings.xml
Auto-merging app/src/main/res/values-ja/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ja/strings.xml
Auto-merging app/src/main/res/values-ka/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ka/strings.xml
Auto-merging app/src/main/res/values-kk/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-kk/strings.xml
Auto-merging app/src/main/res/values-km/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-km/strings.xml
Auto-merging app/src/main/res/values-kn/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-kn/strings.xml
Auto-merging app/src/main/res/values-ko/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ko/strings.xml
Auto-merging app/src/main/res/values-ky/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ky/strings.xml
Auto-merging app/src/main/res/values-lt/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-lt/strings.xml
Auto-merging app/src/main/res/values-lv/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-lv/strings.xml
Auto-merging app/src/main/res/values-mk/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-mk/strings.xml
Auto-merging app/src/main/res/values-ml/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ml/strings.xml
Auto-merging app/src/main/res/values-mr/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-mr/strings.xml
Auto-merging app/src/main/res/values-ms/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ms/strings.xml
Auto-merging app/src/main/res/values-my/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-my/strings.xml
Auto-merging app/src/main/res/values-nb/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-nb/strings.xml
Auto-merging app/src/main/res/values-nl/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-nl/strings.xml
Auto-merging app/src/main/res/values-pa/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-pa/strings.xml
Auto-merging app/src/main/res/values-pl/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-pl/strings.xml
Auto-merging app/src/main/res/values-pt-rBR/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-pt-rBR/strings.xml
Auto-merging app/src/main/res/values-pt/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-pt/strings.xml
Auto-merging app/src/main/res/values-ro/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ro/strings.xml
Auto-merging app/src/main/res/values-ru/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ru/strings.xml
Auto-merging app/src/main/res/values-sk/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-sk/strings.xml
Auto-merging app/src/main/res/values-sl/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-sl/strings.xml
Auto-merging app/src/main/res/values-sq/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-sq/strings.xml
Auto-merging app/src/main/res/values-sr/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-sr/strings.xml
Auto-merging app/src/main/res/values-sv/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-sv/strings.xml
Auto-merging app/src/main/res/values-sw/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-sw/strings.xml
Auto-merging app/src/main/res/values-ta/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ta/strings.xml
Auto-merging app/src/main/res/values-te/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-te/strings.xml
Auto-merging app/src/main/res/values-th/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-th/strings.xml
Auto-merging app/src/main/res/values-tl/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-tl/strings.xml
Auto-merging app/src/main/res/values-tr/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-tr/strings.xml
Auto-merging app/src/main/res/values-uk/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-uk/strings.xml
Auto-merging app/src/main/res/values-ur/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-ur/strings.xml
Auto-merging app/src/main/res/values-vi/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-vi/strings.xml
Auto-merging app/src/main/res/values-zh-rCN/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-zh-rCN/strings.xml
Auto-merging app/src/main/res/values-zh-rHK/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-zh-rHK/strings.xml
Auto-merging app/src/main/res/values-zh-rTW/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values-zh-rTW/strings.xml
Auto-merging app/src/main/res/values/ids.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values/ids.xml
Auto-merging app/src/main/res/values/strings.xml
CONFLICT (add/add): Merge conflict in app/src/main/res/values/strings.xml
...

Every changed file from upstream is shown as a conflict when trying to rebase ..

Where am I going wrong?

For context: I'm trying to run every line of update code under a single stream.

name: Update Fork

on:
  workflow_dispatch:
  push:
    branches: [ "main" ]
  # schedule:
  #   - cron: '0 10 * * *' # runs every everyday at 10:00

permissions:
  contents: write

jobs:
  update_fork:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Forked Repo
        uses: actions/checkout@v2
        with:
          repository: username/forked_repo
          ref: main

      - name: Setup Git
        run: git config --global user.email ${{ secrets.EMAIL }} && git config --global user.name user.name

      - name: Fetch from Upstream
        run: |
          git remote add upstream https://github.com/upstream/upstream.git
          git fetch upstream --tags
          git checkout main
          git rebase upstream/main
          git push -f origin main

Also, I thought this would solve my issue, but it seems to be not solving.

on running git rebase upstream/main || git diff, I'm getting differences which IMO shouldn't cause any issue just because it never caused as an issue in local repo.

++<<<<<<< HEAD
 +def canonicalVersionCode = 1198
 +def canonicalVersionName = "6.9.1.1"
++=======
+ def canonicalVersionCode = 1196
+ def canonicalVersionName = "6.8.3.0"
++>>>>>>> 54629fb86 (my_commit)
theycallmepix
  • 474
  • 4
  • 13
  • Please include your checkout step in the YAML config. – Azeem Jan 21 '23 at 05:43
  • Thanks! Are all those merge conflicts of the form `CONFLICT (add/add)`? – Azeem Jan 21 '23 at 06:07
  • Oh, I never saw that, but yes. every conflict is is of the form `CONFLICT (add/add)` – theycallmepix Jan 21 '23 at 06:10
  • Could it be your local repo is not in sync with the github fork? That might explain why there are conflicts only there. – Cristik Jan 21 '23 at 06:10
  • 1
    That's my initial guess that it needs to be in sync. You may run `git rebase upstream/main || git diff` to verify the diff when `git rebase` fails. – Azeem Jan 21 '23 at 06:12
  • This might be helpful: https://stackoverflow.com/questions/19475387/how-to-handle-fix-git-add-add-conflicts – Azeem Jan 21 '23 at 06:12
  • Ok, it throwsed me about 10000+ lines in comparison. I just updated my question with `diff`. I wonder why would that result in conflict fetching from upstream... – theycallmepix Jan 21 '23 at 06:20
  • @Cristik, it has got nothing to do with local fork. I'm trying to keep my forked github repo updated with upstream. Trying to do the same locally works flawlessly – theycallmepix Jan 21 '23 at 06:26
  • 1
    @theycallmepix: IIUC, your intention is to keep your fork in sync with upstream. The only thing I see is that `action/checkout`'s config `fetch-depth` has the default value `1` but for rebasing, you might need the complete history so you need `fetch-depth: '0'`. See its usage here: https://github.com/actions/checkout#usage. You need to test this in your workflow. Also, I see that you're using `@v2` which has some deprecated dependencies so you need to switch to `@v3` to get rid of those. – Azeem Jan 21 '23 at 06:35
  • Yea, you got it right. I want to keep my forked repo in sync but I've made some changes and hence, I want to preserve them by rebasing it to on top of all the upstream commits – theycallmepix Jan 21 '23 at 06:40
  • Oh s..t! that worked! All I did was switched checkout to `@v3` and added `fetch-depth: '0'`. It rebased without any conflicts! Feel free to add it as an answer and I'll tick it as resolved. – theycallmepix Jan 21 '23 at 06:49
  • @theycallmepix: Awesome! Sure, I'll post an answer shortly. – Azeem Jan 21 '23 at 06:51
  • And the sad part is that I ran out of GH Actions fuel with the last trial that fixed this issue.. – theycallmepix Jan 21 '23 at 07:12

1 Answers1

2

Use fetch-depth: '0' with actions/checkout to fetch the complete history as you're rebasing.

The default is fetch-depth: '1'. See its Usage for more details.

Also, use @v3 of actions/checkout instead of @v2. The @v2 has deprecated NodeJS dependency.

Azeem
  • 11,148
  • 4
  • 27
  • 40