Git squashing and duplicate commits

Hi guys, I'm a bit confused on how a proper workflow should look for squashing. I have the following issue: 1. I'll go and make commits on a feature / fix branch and squash & merge onto the main branch 2. I'll pull my changes from main into my local feature / fix branch to keep it up to date 3. I'll make some more commits on the local feature / fix branch and then do the same steps in 1 & 2 This duplicates the commits since the commits in my local are not squashed. What should I be doing to keep it in sync with main and not duplicate commits?
3 Replies
Jochem
Jochem7mo ago
generally you only squash and merge at the end of a feature branch, and pull from main as you're working on the branch and your colleagues solve issues on the main branch. each new feature gets a new branch that's fresh, and features that are completed have their changes merged and their branches discarded
vince
vinceOP7mo ago
Ohh got ya, I've been creating these long-life feature branches where I'll have multiple squash & merge lifecycles... so I guess it's generally best practice like you were saying to delete the branch after a squash and then create a new one Thank you! Also for anyone in the future who happens to stumble upon this, I deleted my duplicate commits by using git rebase -i HEAD~10 where 10 is the number of commits to look back on in the commit history. Then I deleted the duplicate commits in the terminal by backspacing / deleting each commit message I wanted to delete and then force pushing to main (risky, I know)
Jochem
Jochem7mo ago
yeah, generally you work on a feature in its branch until its done and then squash/merge. THe mess doesn't matter if it's just you looking at it anyway. And feature / bugfix branches are generally just named for the ticket in the bugtracker they're fixing, so that's why you discard the old ones
Want results from more Discord servers?
Add your server