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 '[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][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][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][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

actions/checkout configures Git to send an Authorization header with the token it uses, which is the repository-scoped GITHUB_TOKEN by default. This sounds to me like that header takes preference over any token you give in the remote URL.

Try passing the PAT to actions/checkout with the token parameter (see GitHub - actions/checkout: Action for checking out a repo), to make Git use your PAT instead.