Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manage project backend and frontend in two separate branches or repositories?

I started a project of a mobile app that will have a server-side and the app itself. So, in the master branch I created 2 projects myapp_server and myapp and then I created 2 other branches backend and frontend and I want to push to the separate branches only the project files corresponding to them. But, f.e. in the backend branch, I want to put the project files only, without the parent folder myapp_server itself. Shall I make a git init for the separate branch inside of this project folder? I've made git init only in the directory that contains both projects for the master branch.

How can I actually do that, because I am a bit confused here? Is that even feasible? Is it a bad idea and should I probably have 2 separate repositories for the server and for the app?

like image 445
Milkncookiez Avatar asked Jun 03 '15 18:06

Milkncookiez


2 Answers

TL;DR

should I probably have 2 separate repositories for the server and for the app?

Yes, that's the right way.

Details.

A branch usually tracks a state of the whole working tree (that's a name for everything in the folder under Git control).

This is NOT possible to have in working tree with one repository and two branches:
myapp_server version a AND myapp version b

Only this is possible:
myapp_server version a OR myapp version b

Every project that you have deserves it's own Git repository. This may be either a stand-alone repository or a git submodule. Submodules are quite a complex concept, and an overkill for this situation.

like image 79
Nick Volynkin Avatar answered Sep 28 '22 00:09

Nick Volynkin


The real question here is not if it's possible to hack git to achieve this (the answer is yes) but rather why would you like to do that. What would such worklow allow you to do? Moreover there is nothing wrong with 2 separate repositories for each component.

Btw branch is just a pointer to the commit, which means that yes, you can have completelly unrelated branches in git repository.

like image 36
marbu Avatar answered Sep 28 '22 00:09

marbu