Giter VIP home page Giter VIP logo

react-example-app's Introduction

How to setup your project with a git submodule

This is a quick overview on how to use gitsubmodule in a React project. This is a simple way of sharing code and configuration between multiple apps, which still lets you keep working with a GitHub Flow workflow.

When configuring your new app / repo, you can select one directory that you want to configure to get content from a submodule.

For this guide, we'll use /src/shared

In this example, we'll be using two repos. One ExampleApp and one shared submodule

1. Configure

When configuring your ExampleApp, run the command below.

On the command line:

cd src
git submodule add https://github.com/jlyshoel/react-example-submodule shared

2. How to relate main repo with submodule

When doing a branch, fetch/pull inside the submodule, you'll be asked to make a commit to your main repo. This will specify which commit, from the submodule, should be used with your current commit in the main repo.

Commit from main repo

3. Working with content in submodules

Checking out branches, commit, pull/push are mostly the same as it is for normal git, with exception that you have to be in the submodule directory.

Checkout new branch:

cd src/shared
git checkout -b my_branch

Checkout existing branch

cd src/shared
git fetch
git checkout someones_branch

Commit

Example for committing all changes

cd src/shared
git add .
git commit

Push

cd src/shared
git push

Pull

cd src/shared
git pull

4. Running ExampleApp

If you want to to run the example locally, check out the example git repo and run *npm start.

The ExapmleApp is a simple React app, fetching some content from the submodule.

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

react-example-app's People

Contributors

jlyshoel avatar

Stargazers

 avatar hossein heydari avatar

Watchers

 avatar

react-example-app's Issues

Installing dependencies

Thanks for sharing the example. I have been thinking about using similar structure recently. But one challenge is that how to get the dependencies from the submodules be installed in the app, as the package.json file will not work in sub folders. Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.