简体   繁体   中英

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). I pushed them to github without any problems.

For part3, the course asked to create a new repository for the backend(node.js). I created this repo inside fso/part3 using git init and initialised a node app called phonebook. Now, when I tried to push it to Github, I got this: enter image description here

So, I added my github repo using: 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? git pull origin master git push origin master I'm not sure if this would work, I dont want to lose my work.

Edit: i tried git pull origin main --allow-unrelated-histories and got this

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

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. 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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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