I have two folders in my setup, an express backend and a react frontend which I created with npx create-react-app. I want to push both to the same repository in the same branch but the problem is when I downloaded my react app and check my source control, it split up for some reason. I did git init in the root directory which contained both these folders but it still split them up in the source control:

I'm not sure how to push them to the same repository, some advice or things I should do at the start would be helpful. I'm able to download my backend and create a new frontend since I haven't really done much with my frontend so if a solution which requires me to do something from the get-go of installing react arises, I can do that.
It's likely that your frontend and backend folders each have their own .git folders within. Which would make each of them a git repository as that's where all source control data is kept.
If you are fine with wiping out their history (not your changes/files), then delete the two .git folders and try again from the root directory containing both folders.
Steps to solve this problem:
Remove existing git initialization: cd frontend rm -rf .git
Then go to the backend directory and do the same:
cd ../backend rm -rf .git
Navigate to main folder:
cd ..
Initialize a New Git Repository:
git init
Add Both Folders to the Repository:
git add frontend backend
Commit the Changes:
git commit -m "Add frontend and backend folders"
Connect to GitHub Repository:
git remote add origin
Push the Changes to GitHub:
git push -u origin main
Refer this snapshot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With