Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel isolated feature branches in Git

Tags:

git

The project I am working on at the moment uses Git and the Gitflow Workflow methodology. I have hit a stumbling block with Gitflow which, I believe, originates from the underlying functionality of Git. The problem is regarding feature branches.

With Subversion I could create two branches of our repository, check them out to separate Eclipse projects in my workspace and edit them in parallel. I could edit files in both of these projects in isolation from one another. Changes I made to files in one branch would not be reflected in the other, and vice versa.

With Git, I can also create two feature branches in my repository clone. However whenever I create or edit a file in one branch, if I do not commit those changes before switching to the second branch, those changes also appear in the second branch. Likewise, if I then change the same file in the second branch, and switch to the first again, the file contains all of the changes I have made so far, regardless of which branch I was on when the change was made.

To make matters worse, if I then add and commit my changes in the second branch, the file in the second branch will now contain all changes made from the first and second branches, and the changes disappear completely from the first branch!

Is there any way to have feature branches isolated from one another such that files, and changes to files, are not reflected across both feature branches before committing?

I realise that I could simply commit my changes before switching to another branch, or create a separate repository clone for each feature. However both of these approaches seem to defeat the purpose of having branches.

like image 558
Lord Shacks Avatar asked Feb 02 '26 04:02

Lord Shacks


1 Answers

Unfortunately no. Due to the nature of the branches in git, anything that you have not committed will come along when you switch branches. If you don't want to make a commit, you can also use git stash to undo your changes temporarily.

This is one of the 'features' of git, you are doing your development in one place and do not have to have multiple copies of the projects in different places. You can switch the branches and not change directories or projects.

Sorry, but you are just going to have to be careful switching branches if you want to use git. Or make them into two separate repos.

like image 66
Schleis Avatar answered Feb 03 '26 22:02

Schleis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!