在GitHub中更改存储库名称后如何推送到GitHub

问题描述

我的存储库是Porfolio3,我在GitHub上将其更改为Portfolio(没有3)。我还在努力,但我不想失去它。我进入本地代码,像往常一样键入“ git push”,但是我得到了:

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. 

我尝试了很多类似的事情:

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

但是我明白了

错误:密钥无效:https://github.com/moki929/Portfolio.git

我的git状态:

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)

我试图将原点重命名为目的地。认为可以解决问题。我需要变回原点吗?我只想推送到GitHub。

解决方法

确保您处于“原始”状态,进行获取,变基,合并和推送。如下:

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

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