I am new to git (and version control in general) and I'm trying to work out how best to implement my workflow. I'm working on a (personal) project that involves a lot of "permanent" branches, i.e. completely separate programs that are forked from a common code base and will never be merged into a master branch. (This is because I'm a scientist working on a simulation model, and I'm trying out a lot of new things just to see if they have interesting results. If they do, I currently copy the whole project folder so that I can come back to it later. I'm aiming to use git branches for this purpose instead.)
Because these branches are permanent, I want to know if there's an easy way to take a feature that I've implemented in one branch and transfer it to another, while preserving the differences between the two branches. For example, suppose my repository's tree looks like this:
model_a
/
initial commit
\
model_b
In my case, model_a
and model_b
are using broadly the same simulation code to model two different things. They might differ in the values of some parameters and/or some details in the inner loops of the simulation code, but the general "infrastructure" surrounding it will be the same. Now, while working on branch_a
, suppose I implement a new way of visualising the results:
model_a --- model_a_with_visualisation_code
/
initial commit
\
model_b
What I want to know is, is there a git command I can type that, barring merge conflicts, will result in this:
model_a --- model_a_with_visualisation_code
/
initial commit
\
model_b --- model_b_with_visualisation_code
In other words, I want to take just the commits that were used to turn model_a
into model_a_with_visualisation_code
, and apply copies of those commits onto the end of the model_b
branch. Or at least, I think that's what I want.
It looks like git rebase
should be the tool I want, but I'm having a hard time getting my head round it, and I can't find any examples that illustrate this use case. It also seems that git rebase
deletes the old versions of the commits, rather than making copies of them.
I hope the question is clear. As I said I'm new to git and a lot of the main concepts are still a bit hazy for me. For example, I'm not entirely sure whether the labels in the above trees are meant to be tags or branches or just commits. If I've misunderstood how something is supposed to work, I'd appreciate any clarification.