简体   繁体   English

如何在 github 上将客户端和服务器端项目文件夹作为一个项目(api + 前端)一起推送?

[英]How to push both the client side and server side project folders together as a one project (api + front end) on github?

I have completed my project.我已经完成了我的项目。

My stack:我的堆栈:

Front-End UI => Reactjs
Back-End => Nodejs/Expressjs + MongoDB

And below is my project structure containing both the folders:下面是我的project structure ,其中包含这两个文件夹:

project_Name > client + server

project_Name is the main folder client and server are the separate folders both are inside project_Name folder. project_Name是主文件夹clientserver是单独的文件夹,它们都在project_Name文件夹中。 And inside client and server folder I have installed the respective npm modules (reactjs + nodejs)clientserver文件夹中,我安装了各自的npm modules (reactjs + nodejs)

My API end point is running on localhost:8000 and reactjs on localhost:5000我的API end pointlocalhost:8000上运行, reactjslocalhost:5000上运行

So now I want to add my project to github repository.所以现在我想将我的项目添加到github存储库。 I am confused how to achieve that?我很困惑如何实现这一目标? Do I need to push both client and server side code on separate 2 different gits?我是否需要在单独的 2 个不同的 git 上推送客户端和服务器端代码?

Or或者

I need to upload just project_Name folder containing both side project files?我只需要上传包含双方项目文件的project_Name文件夹? But is it so then how can I do that?但如果是这样,那我怎么能这样做呢? Since before pushing to git , the directory should have the package.json file and node_modules which will be only inside the client and server side folders.由于在推送到git之前,该目录应该包含package.json文件和node_modules ,它们仅位于clientserver端文件夹中。

These are the git commands to push the project I am using:这些是用于推送我正在使用的项目的git命令:

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/vik.........git
git push -u origin main
                

But I don't know in which folder I have to initiate the repository first?但是我不知道我必须先在哪个文件夹中启动repository Let me know the solution please.请让我知道解决方案。 Thanks!谢谢!

If your project that you created has it's own folder then what you would need to do is:如果您创建的项目有自己的文件夹,那么您需要做的是:

Root Folder: Project./client./server根文件夹:Project./client./server

  1. Initiate.git from your ROOT FOLDER.从根文件夹启动.git。
  2. git add. git 添加。 (which then adds all the files) (然后添加所有文件)
  3. git commit... And so on. git 提交...等等。 Feel free to comment if you need any help!如果您需要任何帮助,请随时发表评论!

It'll add all your files in one go, so don't worry so much and it won't push any empty folders.它会将您的所有文件添加到一个 go 中,所以不用担心,它不会推送任何空文件夹。

There's some instances where create-react-app, will create a git repo on it's own.在某些情况下,create-react-app 会自行创建 git 存储库。 On your file explorer look for the hidden files, and be sure to delete that.git folder in your client before pushing your stuff, it'll throw you an error.在您的文件资源管理器中查找隐藏文件,并确保在推送您的内容之前删除客户端中的 that.git 文件夹,它会引发错误。

run NPM install on your main folder, it'll create a package.json for you.在您的主文件夹上运行 NPM install ,它将为您创建一个 package.json 。 Try not to think about it so hard and take it slow.尽量不要想得那么难,慢慢来。

Hopes this helps!希望这会有所帮助!

I think you should use this structure:我认为你应该使用这个结构:

  -projectName: folder
     - frontend: folder
        - package.json
     - backend: folder
        - package.json
     - package.json

For executing the app you can use github actions:要执行应用程序,您可以使用 github 操作:

https://docs.github.com/en/free-pro-team@latest/actions https://docs.github.com/en/free-pro-team@latest/actions

https://github.com/features/actions https://github.com/features/actions

OR或者

You can also use services like heroku or firebase, see my project (it is just a simple project for resolving this problem you are asking for)您还可以使用 heroku 或 firebase 之类的服务,请参阅我的项目(这只是一个解决您所要求的问题的简单项目)

https://github.com/simCecca/InformationVisualizationWorldWide https://github.com/simCecca/InformationVisualizationWorldWide

The structure is:结构是:

 -projectName: folder 
     - frontend: folder 
        - package.json
     backend code
     package.json // containing the BE dependencies and the dependencies for the 
                     deploy in heroku in this case

https://dashboard.heroku.com/ https://dashboard.heroku.com/

I hope I responded to your question, if I'have not, please reply to this response我希望我回答了你的问题,如果我没有,请回复此回复

I solved this problem by adding the.gitignore file in the root folder (in same level as client and server) and inside that this line: node_modules/我通过在根文件夹(与客户端和服务器相同的级别)中添加 .gitignore 文件解决了这个问题,并在该行中添加:node_modules/

this will ignore node_modules of both client and server.这将忽略客户端和服务器的 node_modules。

after that initialize git:之后初始化 git:

  1. Git init Git 初始化
  2. git add. git 添加。
  3. git commit -m 'commit message' git 提交 -m '提交消息'
  4. git push -u origin master git push -u 原点主控

Now you can visit GitHub repositories and confirm there isn't node_modules folder anymore现在您可以访问 GitHub 存储库并确认不再有 node_modules 文件夹

Delete the node_modules and push it from the root.删除 node_modules 并从根目录推送它。

just copy and paste the.gitignore file in both frontend and backend folder, git will not upload node_modules folder in git repository.只需将 .gitignore 文件复制并粘贴到前端和后端文件夹中,git 将不会在 git 存储库中上传 node_modules 文件夹。

After creating two folders named client and backend in a root folder(suppose the name is: my-project ).在根文件夹中创建两个名为clientbackend的文件夹后(假设名称为: my-project )。 Now we would like to push our code to remote like this.现在我们想像这样将我们的代码推送到远程。

a) create a repo named my-project in GitHub (same name as the root folder) b)checking in the terminal of my local to check if it is in the root or not. a)在GitHub (与根文件夹同名)中创建一个名为my-project的 repo b)检查我本地的终端以检查它是否在根目录中。 c)from root: my-project % run all the following commands. c) 从 root: my-project % 运行以下所有命令。

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/vik.........git
git push -u origin main

d) now from the root in each folder[ client and backend ] create a .gitignore file and write node_modules to ignore node_modules if needed. d) 现在从每个文件夹的根目录 [ clientbackend ] 创建一个.gitignore文件并写入 node_modules 以在需要时忽略 node_modules。

e)git add .
f)git commit -m 'all codes is pushed to remote'
g)git push origin main

Now all codes are in the remote.现在所有代码都在遥控器中。 If any code is changed for example in the client .例如,如果在客户端中更改了任何代码。

a) cd client
b) git status
c9 git add ./ file name
d) git commit -m 'client code is pushed'
e) git push origin main

client code is now updated in remote too.客户端代码现在也在远程更新。 Hope it would help.希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM