0

I was working on a branch called main that was based on a remote github repository that does not belong to me. Now, that I have added modifications to this local branch, I want to push it into a remote branch on github that belongs to me.

git status:

On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(venv)

git push --set-upstream origin <my_repository_name>

error: src refspec my_repository_name does not match any
error: failed to push some refs to 'https://github.com/username/my_repository_name.git'

NOTE:

After applying Marcelo's suggestion, I attempted to push to the forked version of the repository and I still received the error message:

remote: Permission to username/my_repository_name.git denied to username.
fatal: unable to access 'https://github.com/username/my_repository_name.git/': The requested URL returned error: 403

UPDATE1:

git remote -v

myrepo  https://github.com/username/my_repository_name.git (fetch)
myrepo  https://github.com/username/my_repository_name.git (push)
origin  https://github.com/username/my_repository_name.git (fetch)
origin  https://github.com/username/my_repository_name.git (push)
upstream        https://github.com/someone_else/my_repository_name.git (fetch)
upstream        https://github.com/someone_else/my_repository_name.git (push)
Rebel
  • 472
  • 8
  • 25
  • Wouldn't it be easier to [fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the github repo and add the changes you want to make? – Marcelo Paco Mar 13 '23 at 01:49
  • I thought I did it and I already made lot of changes :( – Rebel Mar 13 '23 at 01:49
  • If you forked the repo and its the repo you're working with, why not just `push` the changes? It's not going to modify the original repo, if you did in fact fork the original repo correctly. – Marcelo Paco Mar 13 '23 at 01:54
  • Probably I didn't fork it and that's why push is not working. – Rebel Mar 13 '23 at 01:59
  • You could try [this](https://stackoverflow.com/a/25546211/11286032)? – Marcelo Paco Mar 13 '23 at 02:03
  • The second step gives me error remote: Permission to username/some_remote_branch.git denied to username. fatal: unable to access 'https://github.com/username/some_remote_branch/': The requested URL returned error: 403 – Rebel Mar 13 '23 at 02:48
  • Will you provide more details about how you arrived at this situation? When you say "I was working on a branch called development", how did you create the repository that this branch is in? Did you `git clone` a repo from Github? Or did you `git init` a new repo? Or something else? If you did a `git clone`, then what repo did you clone? – Code-Apprentice Mar 13 '23 at 05:12
  • Some of this can be determined from the command `git remote -v`. What is the output of this command? – Code-Apprentice Mar 13 '23 at 05:12
  • I redid the whole thing from fresh by creating a fork on my account and then changed some stuff to push to my version. I updated the post. By development, I just mean "main" in here. – Rebel Mar 13 '23 at 05:22
  • And I git cloned the repo and then changed the main branch. – Rebel Mar 13 '23 at 05:29
  • I git clone this repo: https://github.com/username/my_repository_name.git – Rebel Mar 13 '23 at 05:30

1 Answers1

-2

This error occurs when your local branch is not updated with the remote branch changes. Try

git pull <remote> <branch>

to update remote changes first, then push your local branch commits to the remote. There may be conflicts that you will need to rectify manually.