简体   繁体   中英

How can I have multiple projects with their own local git repositories in one GitHub repository?

I am a university student working on a summer research project with a few colleagues. I am working on one research project that involves an iOS app (built with Swift/Xcode), a Java app (built with IntelliJ IDEA), an Arduino sketch (made with CLion/C++), and a MicroPython file (made with PyCharm/Python). Since I am working with others on a team, and all of these separate codebases produce one finished product, I would like to have one GitHub repository where all of these are stored, each in their own subfolder. Google does this on their examples repository: https://github.com/googlesamples/google-services . They have multiple Xcode projects under the "iOS" folder and multiple Android projects under the "Android" folder, as well as some source code throughout. The Xcode projects appear to all have their own repositories, given the .gitignore file in each of them. Also, all of the projects are on the same branch. How can I achieve this in my own repository? So far I've tried submodules, which seem to not upload the code to GitHub in a way that is accessible. I've also tried adding the GitHub repository as a remote to each project and pushing the projects from there, but I get errors because the master branch on the GitHub repository has changes that are not reflected locally. I would prefer that all the projects are on one branch like they are in the Google repository. Would it be possible for all of the projects to share a local repository, or would that be unmanageable? Thanks.

For your case, ideal practice is to make use of Git Branches , Merge Request and Forks . Branches can be divided into various categories like Feature, Patch, etc.

Also maintaining different projects in one repo, is a REALLY BAD idea. Create Separate Repos.

I won't be explaining here how to use them, as there are already many answers here on Stackoverflow explaining the same, also many articles you will find easily on google.


Just for direct answer to your question: You Can have one repo with multiple directories on local and same in the remote.

I was able to achieve what I wanted by having all of the projects share one local git repository. I agree that this is not a best practice or something that should be done lightly, but in my case, I will be submitting my project in a grant proposal that requires all of the code to be in one repository on the same branch. In order to have all of the projects share a local repository and master branch, the repository must be at the highest folder level of the overall project, and the sub-projects can all be added in a series of subfolders. The easiest way to achieve this is to clone an empty (minus a README file, which is required for cloning) repository to your computer via the GitHub Desktop app or GitHub.com, and then create the subfolders for each project inside of the file explorer/Finder. Subprojects can have as many subfolders as you wish, and each subproject can have its own .gitignore file. Most IDEs will recognize the git repository, so you do not need to create or initialize another git repository in order to use your IDE's built-in VCS tools. I've tested this with Xcode and the JetBrains IDEs, and this works flawlessly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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