Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working on multiple git branches that are dependent on each other

I'm maintaining 4 branches of a project on Git with a structure as below.

  • master
  • student
  • teacher
  • authentication

The problem is I created "authentication" branch the last and added some code from this branch. Now, I switched to "teacher" branch to continue working on it. However, I need some features I added in the "authentication" module to work on "teacher" module. But I'm not finished working on "authentication" module to do a merge. What's the correct way to handle this with git? Thanks.

like image 632
kovac Avatar asked Sep 18 '16 07:09

kovac


People also ask

Can you work on 2 git branches at the same time?

You can have many branches in your repository, but only one of these will be "checked out" as the working-tree so that you can work on it and make changes. git worktree adds the concept of additional working trees. This means you can have two (or more) branches checked-out at once.

Does it support commit across the multiple branches?

b) GIT does not support 'commits' across multiple branches or tags. Subversion allows the creation of folders at any location in the repository layout. c) Gits are unchangeable, while Subversion allows committers to treat a tag as a branch and to create multiple revisions under a tag root.


2 Answers

Sounds like your branches depend on each other and this is causing you problems. Branch depencencies can be caused by the branches getting bigger and bigger and containing too much stuff.

This means that you could benefit from merging smaller things earlier! However looks like you don't want to merge teacher or student to master before either is "complete".

Sounds like you need a place where you can merge the work that is done but might not be ready for a release yet.

If you're considering master to be a branch where only finished features go, maybe you need another branch called develop that is allowed to have not whole features, but smaller steps merged in?

Then you could do something like:

  • do some features related to teacher, merge them to develop
  • start a fresh branch for student-related features, merge them to develop too
  • repeat this until develop looks like something you could release
  • merge develop to master and add a tag a new release

This means that whatever system improvements you do during work on teacher, they will be also quickly available for you during work on student. Same applies to other functionality like authentication.

Don't let your feature branches stay unmerged for more than a few days.
Unmerged work is waste!

More reading: A successful Git branching model

like image 132
Kos Avatar answered Sep 18 '22 14:09

Kos


This often happens while waiting on a slow code review, while your new changes stack up on top in small manageable branches to also be reviewed. Once you get 7 layers deep and have a change at the bottom of the chain it becomes very time consuming to be up to date...

So I created this script that does this merging for you! (it stops on errors or merge conflicts) https://gist.github.com/brennemankyle/6770781bc43c8d2b03988c4c89867871

like image 28
Kyle Avatar answered Sep 22 '22 14:09

Kyle