-2

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

zozo
  • 1
  • 2
  • https://meta.stackoverflow.com/a/285557/5586359 Text, please! http://idownvotedbecau.se/imageofcode. [Edit] your question, copy/paste from the terminal and properly [format](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) it as code. Images are not helpful, they're hard to read and hard to search. Badly formatted code is hard to read. Images are only good to show something non-textual (like colors, fonts, screen positions, etc). – phd Jan 06 '23 at 11:22

1 Answers1

0

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'
Kuldeep Singh
  • 517
  • 6
  • 26
  • Hi, should I use these commands in fso/ or fso/part3/phonebook? – zozo Jan 06 '23 at 09:01
  • @zozo yes please. – Kuldeep Singh Jan 06 '23 at 09:21
  • Yes to what exactly? – zozo Jan 06 '23 at 10:02
  • @zozo as your error was on fso/part3 repository, so you need to run these commands for fso/part3 repository. – Kuldeep Singh Jan 06 '23 at 10:06
  • hi can you check the edit on the post – zozo Jan 06 '23 at 10:16
  • @zozo, can you share, what all branches you have on the server and local for fso/part3 repository? Which branch are you using to make and push changes from local to server ? – Kuldeep Singh Jan 06 '23 at 10:19
  • I added to the post – zozo Jan 06 '23 at 10:25
  • @zozo looks like you are getting confused in directories and repositories. As per your question part1 and part2 should be 2 directories in one repository (fso), but part3 should be an independent repository which you can name like (fsopart3). From your location solution I can see you have created part3 as a directory inside existing repository (fso), which should be a new repository. – Kuldeep Singh Jan 06 '23 at 10:40
  • yes i created a directory called part3 inside fso and initialised a git repo called phonebook inside part3 using git init. So is it possible to push this whole repo as a sub repo of fso? – zozo Jan 06 '23 at 10:43
  • I don't think there is a concept like sub-repo in git. You work on repository or on a directory. Ideally you should not be initializing a repository inside repository, try to keep your repositories in separate folders. – Kuldeep Singh Jan 06 '23 at 10:50
  • @zozo with a single repository you can work on multiple directories independently. Follow below question https://stackoverflow.com/questions/5862233/commit-changes-only-in-one-directory-in-git – Kuldeep Singh Jan 06 '23 at 10:53
  • "I don't think there is a concept like sub-repo in git." Might need to think again. – matt Jan 06 '23 at 15:59