Soccerball123
Soccerball123

Reputation: 879

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.

Upvotes: 3

Views: 9977

Answers (2)

Nikita Choudhari
Nikita Choudhari

Reputation: 1

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.

Upvotes: 0

Ved
Ved

Reputation: 328

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.

Upvotes: 4

Related Questions