Search code examples
gitgithububuntu-18.04github-actionsgit-pull

Can't git pull from remote repo but can git clone in GitHub Actions


So I'm trying to pull a branch from one of my private repositories into GitHub Actions, so I can modify it and push it back into that repository, but it won't let me. Although I can clone the repo, but since I need to push modified files back into the repository, that won't work. The workflow that I ran the commands on, runs on ubuntu-latest. Another thing to note is that when I ran these same commands on my Windows computer, everything runs properly, but for some reason, I didn't need the token or username for the link to work. When I try to pull from the remote repo, I get the following error.

remote: Repository not found.
fatal: repository 'https://github.com/[username]/[repo].git/' not found
Error: Process completed with exit code 1.

But when I try to clone the repository, the command successfully runs. The commands I ran are below.

I create the remote repo with

git remote add repo https://[username]:[token]@github.com/[username]/[repo].git

The token has the repo scope, so it has complete access to repositories. To verify that the command worked, I ran

git remote -v

Which shows the new remote that I added so I know it worked. Next I try to pull the master branch from the remote repo with

git pull repo master --allow-unrelated-histories

Which is where I get the error. The clone command is

git clone https://[username]:[token]@github.com/[username]/[repo].git

This command runs successfully unlike the git pull command.

I have looked at Git - remote: Repository not found and Git Clone - Repository not found, but none of the answers I've tried helped me. Since the commands worked on my local computer, it most likely isn't the commands, and is probably something to do with how GitHub Actions runs the commands or the token.

What I did for the problem to occur

  1. Create a private repository.
  2. Add files, commit, push, etc.
  3. Create a public repository.
  4. Add a workflow file.
  5. Create a personal access token with the repo scope.
  6. Add a secret in the public repo and set it to https://[username]:[token]@github.com/[username]/[private repo].git
  7. Add the commands git remote add repo ${{ secrets.[secret name] }}, git remote -v # To verify that the remote add worked, git pull repo [main/master branch], and ls
  8. commit and push the workflow file and then run the workflow.
  9. Open the session log to see the error

Solution

  • I fixed my problem by setting the .git/config file to what my local .git/config file was, and that solved the problem. I don't know what part of the config file was causing the error, but I do know there was a problem with it.