Reputation: 328
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.
Upvotes: 1
Views: 2740
Reputation: 328
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
Upvotes: 1