rellocs wood
rellocs wood

Reputation: 1481

how to manager multiple git projects into one github repo with different folder

I have such requirement:

Create One GitHub repo A_ROOT with 2 sub-folder B_FOLDER and C_FOLDER,

and now I use git init two local project B and C separately, How can I push local project B to B_FOLDER and project C to C_FOLDER?

EDIT Why I need this : I have one repo on github, I want to add folder like examples under my repo, and each example should be independent and runnable, and when I adjust the examples, I don't want to modify the main project.

Upvotes: 0

Views: 262

Answers (2)

Schwern
Schwern

Reputation: 165446

Why I need this : I have one repo on github, I want to add folder like examples under my repo, and each example should be independent and runnable, and when I adjust the examples, I don't want to modify the main project.

While you can get what you want with submodules, that is an unnecessary complexity. What you describe is a normal project setup.

Simply have an examples/ directory as part of the main project repository. Commit and push changes to it as you would any other directory. There's nothing wrong with "modifying the main project" by committing to the examples/ directory. It is beneficial to keep the examples with the source code so they remain in sync as the project changes. There will be many times when a change to the project code requires an update to the examples.


There may be some circumstances were you want a different process for examples.

If you wish to distribute the examples separately, that should be done with a release tool. I can't tell recommend a release tool for your project, but I can recommend that Git is not a release tool.

If your project has an expensive review or test suite which runs on every commit or Pull Request, change your process to use an abbreviated process for changes which only touch the examples directory. You can check which files were changed in a branch with git diff master --name-only. And you can see which files were changed in the previous commit with git diff-tree --no-commit-id --name-only -r HEAD.

Upvotes: 1

Devs love ZenUML
Devs love ZenUML

Reputation: 11892

Submodules should be able to solve your problem.

It often happens that while working on one project, you need to use another project from within it. Perhaps it’s a library that a third party developed or that you’re developing separately and using in multiple parent projects. A common issue arises in these scenarios: you want to be able to treat the two projects as separate yet still be able to use one from within the other.

...

Git addresses this issue using submodules. Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

Ref: https://git-scm.com/book/en/v2/Git-Tools-Submodules

Upvotes: 1

Related Questions