Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push to another repository in github actions?

In Github Actions, I'm trying to make some changes to a different repo than the repository the workflow belongs to. See this code:

      - name: Generate API module
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |

          git clone https://user:[email protected]/owner/my-repo # This works

          cd my-repo
          git config user.name "user"
          git config user.email "[email protected]"

          git checkout -b api-version-$COMMIT

          touch new-file.sh
          git add new-file.sh
          git commit -m "Add new file"

          git remote -v # Prints:
          # origin ***github.com/owner/my-repo.git (fetch)
          # origin ***github.com/owner/my-repo.git (push)

          git push --set-upstream origin api-version-$COMMIT # This does not work
          git push --set-upstream https://user:[email protected]/owner/my-repo api-version-$COMMIT # This does not work either

I can clone the owner/repo repository just fine. I can checkout the new branch, add the file and commit the changes. The problem occurs when I try to push the changes upstream. That doesn't work at all, and I get this error:

remote: Repository not found.
fatal: repository 'https://github.com/owner/my-repo/' not found

I'm just guessing that it has something to do with authentication. The GITHUB_TOKEN is a personal access token and has all possible permissions.

What gives?

like image 597
Bjørn Olav Jalborg Avatar asked Oct 15 '20 14:10

Bjørn Olav Jalborg


People also ask

How do I push code to another GitHub repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.

How do I push actions on GitHub?

When creating a new workflow in GitHub's action builder the default trigger is the push event. You want to extend this to push and pull request events. Search the line on: [push] in your GitHub Action workflow file. Extend it to on: [push, pull_request] and you're done.

When to use this github action?

When to use this GitHub Action? It is useful in case that you have a GitHub repository with a a directory that you want to push to another GitHub repository using GitHub Actions (automated on push, for example). It is also useful if using GitHub Actions you generate certain files that you want to push to another GitHub repository.

How do I push changes to a remote GitHub repository?

Pushing changes to GitHub 1 Click Push origin to push your local changes to the remote repository. 2 If GitHub Desktop prompts you to fetch new commits from the remote, click Fetch . 3 Optionally, click Create Pull Request to open a pull request and collaborate on your changes. For more information, see " Creating an issue or pull request "

What happens when you push a change to a repository?

People with write permissions can push changes to a repository. When you push changes, you send the committed changes in your local repository to the remote repository on GitHub. If you change your project locally and want other people to have access to the changes, you must push the changes to GitHub.

How do I change the permissions of a GitHub repository?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings . In the left sidebar, click Actions. Under Actions permissions, select an option. Click Save. When you choose Allow select actions, local actions are allowed, and there are additional options for allowing other specific actions:


Video Answer


1 Answers

Not sure if you were able to solve that yet, but figured I'll post one potential solution for future folks that come across that same issue, as did I. I had the same issue, which eventually turned out to be lack of edit permissions on the repo to which I was trying to push. Unfortunately the error message from GitHub (remote: Repository not found.) was really unhelpful in pointing out the real issue (I assume it's a matter of obfuscation for security purposes, but then- if that account was already able to clone the repo and have read access to it- what's the point of obfuscation? This is obviously an authorization issue for an already authenticated user 🤷🏻‍♂️). Either way- I was able to solve this on my end by gaining write access to the repo. After getting the needed permissions - I was able to successfully push into that repo.

like image 167
Moshe Shitrit Avatar answered Oct 13 '22 07:10

Moshe Shitrit