What's a good strategy for dealing with multiple in-progress GIT branches?
-
I am fairly new to GIT. I've only used it for a few months. I have a lot more experience with SVN, which we don't use in my current job. But even when I worked with SVN, I tended to use it in pretty simple ways, without a lot of branching. Where I work, we're told to make new branches in GIT whenever we are making major changes to the code base. This makes perfect sense to me. But it leaves me in a mess quite often, and I'm wondering if there's a better way I could be working. What happens is this: I realize that I have to make major changes, so I make a branch. I spend five days coding in that branch, during which I make major changes to maybe 40 files. My boss then asks me to make some changes to production code (back in the master branch) -- crucial bug fixes or whatever. I can't merge my new branch back into the master at this point, because I haven't finished the coding I'm doing in the new branch. It's currently way too unstable and buggy to be merged. So, reluctantly, I go back to the master and work on the production changes. I spend five days doing that, making tons of changes to the master-branch's code. Some of these changes are to the same 40 files that I've been working on in the branch -- or at least to some of those files. Some are to completely different files. I am now in a mess. The branch is no longer the-master-plus-some-changes. It's now wildly different from the master. But I will, at some point, need to move the work I did in the branch into the master, once I'm able to get back to it and complete it. Of course, now that the master has massively changed, some of the work I did in the branch should be changed to interact better with the master's changes. But those changes aren't in the branch. How do I proceed? Is there some really good diff tool I should be using (OS X)? Is there a flaw in my whole way of using GIT? This seems to happen about once a month, and it's driving me crazy. I dread reconciling the two branches. My coworkers don't have any advice, because their jobs are much "quieter" than mine. They tend to work for a long time in one branch and are able to make incremental changes without dealing with "alternate universes" very often. When they do branch, they are generally able to complete their task in that branch quickly and then merge it into the master. So they're always just doing active work in one branch. And as soon as that's done, they can merge it back in. That doesn't work for what I'm asked to do. I often have to spend days in a branch and then go back to the master before my branch work is finished.
-
Answer:
Your root problem isn't technology, it's project management. If you're being asked, often, to switch back and forth between multiple tasks that affect the same code, of course you're going to have to do a lot of merging. Ideally your boss should be able to help with this. So you've probably already tried that, and it isn't working. Here are some technologies that can reduce the pain: Well-designed, modular code. If you have large files and complex classes, that increases the odds that two code changes will interfere with each other. This is yet another reason to aim for small files, small classes, small methods, and separation of concerns. A great test suite. The worst thing about merging isn't all those conflict markers you have to resolve; it's the subtle problems that git doesn't notice. In one branch, you changed the signature of a method and all its callers; in another branch, you added a caller using the original signature. There's no immediate line-editing conflict, so git won't warn you. But a good set of tests can tell you when the new caller stops working after the merge. There are probably great merge tools. I can't make a recommendation there, but a quick Google search turned up FileMerge (part of Apple's free Developer Tools), Changes (shareware), DiffMerge (possibly free?), and a two-year-old list of merge tools one person knew about (http://gitguru.com/2009/02/22/integrating-git-with-a-visual-merge-tool/). Perhaps another answerer can give some advice on this.
Erik Ostrom at Quora Visit the source
Related Q & A:
- What's a good search engine for a large corporate intranet?Best solution by Software Recommendations
- What's a good 15-25 watt starter amp that I can buy for home practice that is cheap and has good features?Best solution by Yahoo! Answers
- What's a good site to make a good resume?Best solution by Yahoo! Answers
- What's a good netbook out in the market that's not too expensive?Best solution by ChaCha
- What's a good title for a To Kill a Mockingbird essay?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.