为什么我不能将本地Git存储库推送到我的遥控器上? [英] Why can't I push my local Git repo to my remote?

查看:43
本文介绍了为什么我不能将本地Git存储库推送到我的遥控器上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git新手,我对某些事情感到困惑.我正在尝试将当前项目的所有代码放入本地存储库中,然后将其推送到远程存储库中,以便即使本地计算机严重崩溃也可以对其进行备份.

I'm a novice git user and I'm getting rather confused about something. I'm trying to put all of the code for my current project in a local repo and then push it to the remote repo so that it is backed up even if my local machine crashes hard.

我已完成以下操作,将项目中的所有文件添加到本地存储库中:

I've done the following to add all the files in my project to the local repo:

$ git init
$ git config user.name 'My Name'
$ git config user.email my-email@example.com
$ git add .
$ git ls-files

当然,仅需确认其中的最后一个就可以确认文件是否在本地存储库中,并且确实可以找到文件在其中.(我可能需要添加一个gitignore,但稍后再做.)

The last of those is, of course, only needed to confirm that the files are on the local repo and, sure enough, the files are there. (I probably need to add a git ignore but I'll do that later.)

所以现在我想将本地存储库推送到远程存储库.我已经在GitHub中设置了一个存储库,并使用README对其进行了初始化.假设其名称为MyID \ vuetify02.我执行了以下命令,首先添加远程仓库,然后确认已添加远程仓库:

So now I want to push the local repo to a remote one. I've already set up a repo in GitHub and initialized it with a README. Let's say its name is MyID\vuetify02. I did the following commands, first to add the remote repo, then to confirm that the remote repo was added:

$ git remote add remote vuetify02 https://github.com/MyID/vuetify02
$ git remote -v

这些命令的后一个给了我:

The latter of those commands gave me this:

vuetify02       https://github.com/MyID/vuetify02 (fetch)
vuetify02       https://github.com/MyID/vuetify02 (push)

到目前为止,太好了.这是我所期望的,似乎可以确认它可以看到远程回购并且对它的存在感到满意.

So far, so good. This is what I expected and it seems to confirm that it sees the remote repo and is satisfied that it exists.

然后,我尝试执行此操作,假设我现在已经与远程回购建立了连接并建立了一个别名,该别名将vuetify02映射到我想要的确切远程回购中:

Then I tried doing this, assuming that I'd now established a connection with my remote repo and established an alias that mapped vuetify02 to the exact remote repo I wanted:

git push vuetify02

但出现此错误:

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 vuetify02 master

这个git的方法是让我确定应该将其用于远程回购的哪个分支?到目前为止,我那里只有一个master分支,因此我假设如果不指定分支,它将默认为该分支.不过,我可能是错的,即使只有一个分支,也需要明确告知要使用哪个分支.无论如何,我尝试执行该确切命令并得到:

Is this git's way of having me establish which branch of the remote repo it is supposed to use for my push? I only have a master branch there so far so I assumed it would default to that if I didn't specify a branch. I'm probably wrong on that though and it needs to be told explicitly what branch to use, even if there is only one. Anyway I tried doing that exact command and got:

remote: Repository not found.
fatal: repository 'https://github.com/MyID/vuetify02/' not found

我很困惑!为什么找不到存储库?我知道那里有远程仓库,我在命令中看不到任何错字,所以应该可以,对吧?

I'm baffled! Why can't it find the repository? I know the remote repo is there and I can't see any typos in the command so it should work, right?

对于一些我不正确理解的问题,我将不胜感激.

I'd appreciate some clarification on what I'm not understanding correctly.

推荐答案

您正在使用https URL,因此您也需要在远程URL中传递用户详细信息

You are using the https URL so you need to pass the user details too in the remote url

请先做-

git remote set-url vuetify02 https://<MY_USER_NAME>@github.com/<MY_USER_NAME>/vuetify02.git 

这篇关于为什么我不能将本地Git存储库推送到我的遥控器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆