简体   繁体   English

将我在另一个存储库中使用 git init 初始化的存储库推送到 github

[英]Pushing a respository I initialised with git init inside another repository to github

I am currently doing course called fullstackopen for which I created a repository on Github called fso and cloned it locally using ssh. Inside fso, I created directories for different parts(part1, part2) and created react projects inside them (using create-react-app).我目前正在学习名为 fullstackopen 的课程,为此我在 Github 上创建了一个名为 fso 的存储库,并使用 ssh 在本地克隆了它。在 fso 中,我为不同的部分(第 1 部分、第 2 部分)创建了目录,并在其中创建了反应项目(使用 create-react-应用程序)。 I pushed them to github without any problems.我毫无问题地将它们推送到 github。

For part3, the course asked to create a new repository for the backend(node.js).对于第 3 部分,课程要求为后端(node.js)创建一个新的存储库。 I created this repo inside fso/part3 using git init and initialised a node app called phonebook.我使用git init在 fso/part3 中创建了这个 repo,并初始化了一个名为 phonebook 的节点应用程序。 Now, when I tried to push it to Github, I got this: enter image description here现在,当我试图将它推送到 Github 时,我得到了这个:在此处输入图片描述

So, I added my github repo using: git remote add origin所以,我使用以下方式添加了我的 github 回购: git remote add origin

After this when I tried to push again, I was prompted for my username and password but support for password authentication has been removed.在此之后,当我再次尝试推送时,系统提示我输入用户名和密码,但已删除对密码身份验证的支持。 I tried pushing using personal access tokens and got this: enter image description here我尝试使用个人访问令牌进行推送并得到了这个:在此处输入图像描述

Can I run the following in my part3/phonebook (phonbook-backend) directory?我可以在 part3/phonebook (phonbook-backend) 目录中运行以下命令吗? git pull origin master git push origin master I'm not sure if this would work, I dont want to lose my work. git pull origin master git push origin master我不确定这是否可行,我不想失去我的工作。

Edit: i tried git pull origin main --allow-unrelated-histories and got this编辑:我尝试了 git pull origin main --allow-unrelated-histories 并得到了这个

pushing after this results in the same error在此之后推动会导致相同的错误

this is what my directory structure looks like locally.就是我的目录结构在本地的样子。 Im trying to push part3 to my github repo我正在尝试将第 3 部分推送到我的 github 存储库

Your last error is ' updates were rejected because the remote contains work '您的最后一个错误是“更新被拒绝,因为远程包含工作

This happens when your repository gets initialized with additional files like README or GITIGNORE.当您的存储库使用 README 或 GITIGNORE 等其他文件进行初始化时,就会发生这种情况。 To resolve this, first you need to pull your changes from server, so you can use below command:要解决这个问题,首先您需要从服务器中提取您的更改,因此您可以使用以下命令:

'git pull origin main --allow-unrelated-histories'

Then you can push your changes to server using below command:然后您可以使用以下命令将您的更改推送到服务器:

'git push -f origin main'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM