I recently started working on a project which uses Git for version control. I have to fix two defects, Defect1
and Defect2
. Fixes for Defect1
and Defect2
need changes to File1
and File2
respectively. These two files are unrelated to each other.
I want to work on each defect in a separate Git branch. I created two branches, fix_Defect1
and fix_Defect2
, and want to work on them independently. The fixes are complex, so I cannot complete one fix and commit it before switching to the other. I observe that when I switch from fix_Defect1
to fix_Defect2
, any changes made to File1
also appear (and vice versa). Is there some way to avoid this from happening?
From the Git help, I could not figure out any way. I also searched on SO for git work with multiple branches, and found Git and working on multiple branches and Using git with multiple branches at once, which are close but somewhat different from my question.
I can clone multiple copies of the repository per branch in a separate directory, but it seems like I would be missing the full power of Git branching by doing so, besides wasting disk space. Could you please suggest a good approach to handle this scenario?