1

My repository was Porfolio3, and I changed it to Portfolio (without the 3) on GitHub. I'm still working on it, and I don't want to lose it. I went into my local code and typed "git push" as usual but I got this:

D:\GitHub\01 Portfolio> git push To https://github.com/moki929/Portfolio ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/moki929/Portfolio' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

I've tried many things like:

PS D:\GitHub\01 Portfolio> git remote add origin-push $(git config https://github.com/moki929/Portfolio.git)

but I get this

error: invalid key: https://github.com/moki929/Portfolio.git

My git status:

PS D:\GitHub\01 Portfolio> git status On branch master Your branch is ahead of 'destination/master' by 3 commits. (use "git push" to publish your local commits) 

I tried to rename origin to destination. Thinking that would fix it. Do I need to change back to origin? I just want to push to GitHub.

4
  • What about git remote --set-url origin <url>? Commented Oct 13, 2020 at 4:46
  • 3
    The error message told you to sync the remote first. You could try git fetch --all first, then git rebase origin/master or git merge origin/master. Then you can try to git push again. Commented Oct 13, 2020 at 5:49
  • PS D:\GitHub\01 Portfolio> git fetch --all Fetching destination From github.com/moki929/Portfolio Fetching origin-push ...Portfolio> git rebase origin/master fatal: invalid upstream 'origin/master' ...Portfolio> git merge origin/master merge: origin/master - not something we can merge ...Portfolio> git push To github.com/moki929/Portfolio ! [rejected] master -> master (non-fast-forward) ... ...Portfolio> git remote --set-url origin github.com/moki929/Portfolio.git error: unknown option `set-url' Commented Oct 13, 2020 at 23:35
  • It worked! I had to change it back with: git remote rename destination origin ... all those errors above didn't happen again. Commented Oct 13, 2020 at 23:49

1 Answer 1

2

Make sure you are in "origin", fetch, rebase, merge, and push. As below:

git remote rename destination origin git fetch --all git rebase origin/master git merge origin/master git push 

Thanks Chuck Lu! https://stackoverflow.com/users/13338936/chuck-lu

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.