将我的第一个项目从我的Git推送到我的在线GitHub存储库



我是GitHub新手。我在我的电脑上创建了一个名为";SpettroCorpoNero";,它包含一个文件";SpettroCorpoNero.ipynb";。现在我想将它初始化到我的GitHub帐户中。为此,我在git(Linux上(上写了以下几行代码:

git init (which should initializate my project)
git status (Which shows in red the new files I would like to replicate on my GitHub account)
git add SpettroCorpoNero.ipynb (which is the list of file to put in the "basket")
git commit -m "That's BlackBodySpectrum" (That looks like another basket to put in)
git push

代码看起来一直工作到代码的倒数第二行。比下面的错误信息我已经收到

fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>

为了解决这个问题,我做了不同的尝试,比如按照错误消息中的建议,用我的昵称(Stefanovic80(跟随推送。但我在所有这些方面都失败了,现在我感到困惑和迷失方向。

有人能解决这个问题吗?

正如命令所说,您需要告诉它推送到哪里,默认名称为origin,url与repo的克隆url相同。

git remote add origin https://GitHub.com/account/repo.git

您需要在GitHub上有一个基础存储库,以便首先使用此路径将您的回购推送到。

如果你安装了githubcli,你可以通过调用一次创建目标回购并设置远程

gh repo create 

来自本地git存储库。它将在GitHub上创建回购,并设置您的本地设置,这样您就可以直接推送回购。

另请参阅:

  • https://cli.github.com/manual/gh_repo_create

简单地说,您只需要设置您的遥控器。如果你去你的远程存储库(很可能是空的(,你会看到一个你可以复制的URL,看起来像:

https://github.com/my-username/my-repo-name

然后,在命令行中,运行命令

git remote add origin https://github.com/my-username/my-repo-name

您可以将origin替换为任何您喜欢的名称,但这将是您的远程连接的名称。

最后,您需要将main(或分支的名称(推送到远程源:

git push -u origin main

最新更新