I want to create a sub-branch from an existing branch. My desired history would look like this:
--- master ----
\-*--* model -*-*-
\--*-- subbranch_model --*--
Does the subbranch_model will get the whole history from its parent branch model?
If it is, how can I accomplish that?
Yes, that is possible. You just base subbranch_model on model (make model starting-point of history for subbranch_model). It can be done simply like this: git branch <branchname> [<start-point>]. You can also do it during checkout into a new branch: git checkout -b <branchname> [<start-point>].
git branch subbranch_model model
^-- branchname ^
`-- start-point
See https://git-scm.com/docs/git-branch for details.
The new branch (subbranch_model) will have all history up to <start-point> (model) but there's no "subbranch" it is just "a branch" that shares common history to certain point.
If you intend making changes to model and subbranch_model at same time, keep both these branches going you will also need to carry over any new changes made to model back to subbranch_model somehow (e.g. continuously rebase subbranch_model on top of updated model). See https://git-scm.com/docs/git-rebase for more details on rebase.
To subsequently keep the branch up to date with newer changes to model, you can do
git rebase model
To subsequently keep the branch up to date with master, you can do
git rebase master
When you refer to history, you may want to use the term 'changes' instead. In some sense there is only one "history", however with branches there are many changes per branch. Note that all branches contain all the 'history' at the point that they diverged (the branch was made).
Note that git merge is another way to bring in changes but git rebase is generally preferred because when you get conflicts it's generally easier to resolve them under the rebase model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With