question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failing to commit to fork in pull requests

See original GitHub issue

Trying to file an issue, because I feel like there must be a solution, but I’ve been unable to find it so far.

I want to create an action that runs on specific pull requests (based on the label), and commit changes (i.e. fixes) on the same branch.

I tried with the default settings, and when I try to commit, I get this error

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

Error: Process completed with exit code 128.

After searching in existing issues, I found the suggestion to clone with ref: ${{ github.head_ref }}. And that works perfectly, but only if the pull request is coming from the same repository. If I try to run it on a pull request coming from a fork, I get this error instead, still in the cloning phase (Fetching the repository):

   /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/test_pr_outside*:refs/remotes/origin/test_pr_outside* +refs/tags/test_pr_outside*:refs/tags/test_pr_outside*
  The process '/usr/bin/git' failed with exit code 1
  Waiting 11 seconds before trying again
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/test_pr_outside*:refs/remotes/origin/test_pr_outside* +refs/tags/test_pr_outside*:refs/tags/test_pr_outside*
  The process '/usr/bin/git' failed with exit code 1
  Waiting 13 seconds before trying again
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin +refs/heads/test_pr_outside*:refs/remotes/origin/test_pr_outside* +refs/tags/test_pr_outside*:refs/tags/test_pr_outside*
  Error: The process '/usr/bin/git' failed with exit code 1

If I try adding fetch-depth: 0, the error changes to

Determining the checkout info
  /usr/bin/git branch --list --remote origin/test_pr_outside
  /usr/bin/git tag --list test_pr_outside
  Error: A branch or tag with the name 'test_pr_outside' could not be found

test_pr_outside it’s indeed the name of the branch on the fork, but it’s clearly not available in origin.

Any suggestion?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:5

github_iconTop GitHub Comments

4reactions
flodolocommented, Mar 7, 2021

I think I’ve figured out how to ensure that cloning works even from forks.

      - name: Clone repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: ${{github.event.pull_request.head.ref}}
          repository: ${{github.event.pull_request.head.repo.full_name}}

Working:

  • I can commit if the branch comes from the main repository
  • I can at least clone if the branch comes from a fork

Not working:

  • Commit to the fork’s branch.

Even if “Allow changes by maintainers” is enabled (i.e. actions are not enabled on the fork), I get a fatal: unable to access 'fork_repo': The requested URL returned error: 403. Do I need an SSH_KEY to solve that, because the action token is not sufficient?

EDIT: never mind, tried with ssh-key and getting exactly the same error 😔

2reactions
Siddharth-Ashricommented, Jun 15, 2022

Hi this only seems to work for public repos. Private repos don’t seem to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

is it possible to commit to a fork without polluting a previous ...
I "forked" a repository intending to do some work, make a change to my own fork, and then create a pull request back...
Read more >
Problems with Pull Requests and How to Fix Them
Someone (optionally) creates a fork, authors some commits, pushes them to a branch, then creates a pull request to track integrating those ...
Read more >
Adding Commits to Someone Else's Pull Request - Tighten Co.
Step 1: Clone · Step 2: Add a remote · Step 3: Fetch from this new remote · Step 4: Check out their...
Read more >
How to locally fetch and checkout a pull request
To merge, we recommend using the merge button in the pull request. You can also merge locally and push the merge up to...
Read more >
Lifecycle of a Pull Request - Python Developer's Guide
CPython uses a workflow based on pull requests. What this means is that you create a branch in Git, make your changes, push...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found