I am working on a git repository where I do not have any merge write. There are large requirements which requires at least 1-3 weeks to complete. I take out a branch from master and do my changes in it. During this time I generate multiple commits at the end of the day and ensure my code is pushed to remote branch.
Multiple commits on branch code doesn't look great so followed the below link to squash them into one commit using rebase command.
https://blog.carbonfive.com/2017/08/28/always-squash-and-rebase-your-git-commits/
This doesn't seems to be a very good option as the process is long and there are chances of mistake as well.
My Question is, is there any other option I can follow?
Another possible course of action, somewhat simpler and less error-prone than an interactive rebase in some contexts, is to just undo the commits and re-commit just once for the whole lot. I also find it quicker.
Let's assume this example tree with 2 branches, master
and complex-feature
A-<-B-<-C <<< master
\
D-<-E-<-F-<-G-<-H-<-I-<-J-<-K <<< complex-feature
Before just merging this long list of commits (D,E,F,G,H,I,J,K
), you could do the following :
git checkout complex-feature
git reset --soft B
git commit -m "Global message for commits D through K"
And the tree would look like this afterwards :
A-<-B-<-C <<< master
\
L <<< complex-feature
...where commit L
contains the sum of all changes from D
through K
.
However, as noted by others, multiple small commits are not a problem, and grouping too many things together can also have nasty side effects. Be sure to discuss with your coworkers and adapt to your workflow.