有时候我们会搞坏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.
那么可以通过如下的指令修复:
- 删除本地的远程仓库地址
$ git remote rm <repo-name>
- <repo-name>: 仓库名称, 默认为origin
- 添加远程仓库地址到本地
$ git remote add <repo-name> <git-url>
- <git-url>: git仓库的地址, 可以是HTTPS地址, 也可以是SSH地址
- 这个时候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