Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I commit both my frontend and backend folders to github as one folder?

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:

enter image description here

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.

like image 486
Soccerball123 Avatar asked Nov 27 '25 18:11

Soccerball123


2 Answers

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.

like image 161
Ved Avatar answered Nov 30 '25 13:11

Ved


Steps to solve this problem:

  1. Remove existing git initialization: cd frontend rm -rf .git

  2. Then go to the backend directory and do the same:

    cd ../backend rm -rf .git

  3. Navigate to main folder:

    cd ..

  4. Initialize a New Git Repository:

    git init

  5. Add Both Folders to the Repository:

    git add frontend backend

  6. Commit the Changes:

    git commit -m "Add frontend and backend folders"

  7. Connect to GitHub Repository:

    git remote add origin

  8. Push the Changes to GitHub:

    git push -u origin main

Refer this snapshot.

like image 36
Nikita Choudhari Avatar answered Nov 30 '25 12:11

Nikita Choudhari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!