Reputation: 485
I have two applications I want to include as part of the same repository. An Express backend and a React frontend. The React frontend was created using npx create-react-app
. Creating a React app in this way also creates a .git
folder and a .gitignore
file in the folder of my React app. After running git init
on the parent folder of what I want to include I am left with a repository that contains two .git
folders:
.git
.gitignore
README.md
react-frontend
.git
.gitignore
README.md
express-backend
After attempting to add files to the repository with git add .
git warns me about the second .git
folder:
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> youtube-dl-react-frontend
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached youtube-dl-react-frontend
hint:
hint: See "git help submodule" for more information.
I am not sure what to do here. What is a submodule and is it really what I want to use to include my React app? Or should I just delete the .git
folder from the React folder? Or is there something different I should be doing here?
I also tried commiting, then running git push -u origin master
to see if I would be able to push my changes, but I was unable to:
error: failed to push some refs to 'my project url'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Upvotes: 1
Views: 4719
Reputation: 325
Accepted Answer no longer works or potentially never did because you cannot push your commits onto an existing branch of a new repo most of it is good until you actually push:
> git pull --allow-unrelated-histories
is the main thing that joins the local branch to the remote repo's main
> ... [email protected]:{org}/{repo}.git
is an ssh repo connection
start here:
git init
git remote add origin [email protected]:{org}/{repo}.git
git add .
got commit -m "init"
git branch --set-upstream-to=origin/main main
git pull --allow-unrelated-histories
now merge your .gitignore file (keeping the react generated one) and any others you please.
git add .
git commit -m "save me jebbers"
git push
Upvotes: 0
Reputation: 48
A git folder contains git config files and commits and all changes in git repository if you want to make your project directory work with your own git repository delete the .git folder that react made for you and then use
Git init
Git remote add origin (repo url)
Git add .
Git commit -m "your message"
Git push -u origin master
Upvotes: 1