当前位置:   article > 正文

小白入职第二天遇到 Git 无法将代码推送到远程仓库的问题_git push 远端没有仓库

git push 远端没有仓库

项目场景:

小白刚刚入行,在公司第一天使用Git时遇到了问题

git push 
  • 1

当我时使用git push这个命令把我的代码推送到远程仓库时发生了错误。
错误如下:


问题描述

使用 git push 命令将我的代码推送到远程仓库时,无法将代码推送到远程仓库

The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream master master

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

原因分析:

将英文翻译后发现这个问题是因为我正在尝试将本地的当前分支推送到远程仓库时,Git 发现当前分支没有设置上游分支(upstream branch)。


解决方案:

我们可以使用这行命令来将远程分支设置为上游分支。

git push --set-upstream origin master
  • 1

这会将 “master” 分支推送到名为 “origin” 的远程仓库,并将其与远程的 “master” 分支关联起来。之后,你就可以使用简单的 git push 命令来推送你的更改,不需要再次指定远程分支和本地分支的名称。

但是

我们使用这行命令的前提是我们要有一个名为 origin 的远程仓库(这是没有这个仓库的提示):

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists. 
  • 1
  • 2
  • 3
  • 4
  • 5

所以我们可以使用下面这行命令来设置:

git remote add origin <远程仓库的URL>
  • 1

一定要记得把 “<远程仓库的URL>” 替换为你实际使用的远程仓库的 URL。

如果你怕URL写的不对,可以通过下面这个命令来确认一下:

git remote -v
  • 1

关联成功之后就可以成功的把代码推送到远程仓库啦。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/452732
推荐阅读
相关标签
  

闽ICP备14008679号