【问题标题】:How to push to GitHub after changing the repository name in GitHub在 GitHub 中更改仓库名称后如何推送到 GitHub
【发布时间】:2021-01-27 09:03:02
【问题描述】:

我的存储库是 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 --set-url origin <url> 呢?
  • 错误信息告诉你先同步遥控器。您可以先尝试git fetch --all,然后再尝试git rebase origin/mastergit merge origin/master。然后你可以再次尝试git push
  • 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 - 不是我们可以合并的东西 ...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'
  • 成功了!我不得不将其改回: git remote rename destination origin ... 上面的所有错误都没有再次发生。

标签: git github repository


【解决方案1】:

确保您处于“原点”、获取、变基、合并和推送。如下:

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

感谢卢查克! https://stackoverflow.com/users/13338936/chuck-lu

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2021-08-01
    • 2013-07-12
    • 2022-10-13
    相关资源
    最近更新 更多