[Git]远程仓库地址-更新upstream

有时候我们会搞坏Git仓库的远程地址
$ git push
Access denied
exec request failed on channel 0
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
那么可以通过如下的指令修复:

  1. 删除本地的远程仓库地址

$ git remote rm <repo-name>

  • <repo-name>: 仓库名称, 默认为origin
  1. 添加远程仓库地址到本地

$ git remote add <repo-name> <git-url>

  • <git-url>: git仓库的地址, 可以是HTTPS地址, 也可以是SSH地址
  1. 这个时候push会出现如下错误:
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

可通过如下指令修复 upstream

$ git branch --set-upstream-to=origin/master master



补充常见的新建仓库的方式:

  • Git 全局设置
    git config --global user.name "<your-username>"
    git config --global user.email "<your-email>"

  • 本地克隆远程
    git clone <git-repo>
    cd <cloned-directory>
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master

  • 本地创建仓库连接到远程仓库
    cd <local-repo-folder>
    git init
    git remote add origin <git-repo>
    git add .
    git commit -m "<commit-msg>"
    git push -u origin master

  • 已存在的Git版本库连接到远程仓库
    cd <local-repo-folder>
    git remote rename origin old-origin
    git remote add origin <git-repo>
    git push -u origin --all
    git push -u origin --tags

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 远程仓库 到目前为止,我们已经掌握了如何在Git仓库里对一个文件进行时光穿梭,你再也不用担心文件备份或者丢失的问题...
    归云丶阅读 1,980评论 0 5
  • 1.git的安装 1.1 在Windows上安装Git msysgit是Windows版的Git,从https:/...
    落魂灬阅读 12,716评论 4 54
  • 程序员七年了!破了程序员单身狗的法制,结婚生孩子,也步入了三十岁的年代,在这个说老不老,说年轻不年轻的年龄,也不知...
    春溪竹阅读 274评论 0 0
  • 中原小城的火车站,站厅都不太大,或新或旧,共同的特点,似乎就是没有空调。 夏季的站厅,不时的涌入三五成群的旅客。柱...
    九月斜阳阅读 310评论 0 0