If you look back your git commit history as the diagram below, do you prefer the left or the right side of the commit traces?
Obviously the left side of item looks neater. Is that achievable? For a small size of development team, I would say Yes. It requires some level of of planning as below.
- Partition the project into features that will involve distinct decouple codes as much as possible. Of course the based architecture of the app is crucial to determined if such partition is easily feasible or not.
- For each feature, try to make sizable partial (releasable) milestones where changes could be committed frequent to the main branch. Avoid a major changes on a branch decoupled from the main branch for a long time.
- Most importantly. Perform rebase prior to merging your code into the main branch. Try avoiding the temptation to merge if you know there are new codes already merged into main branch after your branch off. Frequent rebase before planning for a merge would help minimize potential numerous conflicts.
If you are not sure what rebase is, refer to the below site.
Merging vs. Rebasing - The golden rule of rebasing
Compare git rebase with the git merge command and identify all of the potential opportunities to incorporate rebasing…
There are caveats for point 1 and 2, where it can’t be fulfilled. This is especially true for huge complex projects across features, or major refactor of the base architecture work. This shouldn’t happen that frequent though… else I would think the base architecture in place is flawed.
But for item 3, lots of time is just a matter of discipline. If it becomes the habit of the team, things might not be perfect, but it definitely would be much neater.
Having said that, there are some caveat for rebase as below: -
- When trying to rebase, there are numerous conflicts, that need to be resolved over and over again. This could be due to some major conflicts that happens at early of in the branch off. In this scenario, a merge might better than doing the rebase. Saving some time at the expense of neatness. Such scenario could be reduced having step 1 and 2 above handled well, and also a frequent rebase performed.
- If there are someone else working on your remote branch, that you plan to rebase, don’t do it! You’ll end up messing up the other person local branch after you preform a force push. You should always know who is working on your branch and discuss with them closely before before doing rebase and force push.
Discipline is the soul of an army. It makes small numbers formidable; procures success to the weak, and esteem to all. — George Washington