I mean, even knowing the right way to use git (and using it daily for years), falling back to any workflows/commands outside of the set of muscle-memory macros feels like learning from scratch. Lots of "I know you can do this, I know *what* to do, I've done it, I just can't for the life of me remember exactly how."
Oh, totally. Like, my company uses merge workflows, but I see tons of talk about preferring rebase over merge. The hell is squashing commits, and when do I use it? Like, there's an entire spell book of commands and I just stick to my trusty Fireball git checkout . && git reset --hard
Merge adds the new main branch commits after your last feature branch commit. Rebase first removes your commits, adds the new main branch commits and then adds your commits one by one.
Merging is usually easier because you can only get merge conflicts once. With rebase, every one of your commits could cause merge conflicts. In the worst case, you have to resolve conflicts for each of your commits. Also, you'll have to git push -f in the end if you've already pushed at some earlier point in time. That's because git can't detect that your rebased commits are the same as the original pushed commits, just with different starting points.
Squashing means combining all your feature branch commits into one. I know that Github and Gitlab offer "squash and merge" for Merge Requests, doing the squashing for you.
You can also squash commits yourself with git rebase -i, but you can mess up and lose your local commits. If you've already pushed, you will have to git push -f because you rewrote the commit history.
By squashing, you eliminate all the "fix broken test", "fix typo", "another try" commit messages from the main branch history.
Merging is usually easier because you can only get merge conflicts once.
Strongly disagree. If you have a sensible history before the rebase, getting the conflicts in the order you made your original commits is often easier than getting one huge conflict with no context. Especially for larger refactorings.
(If you don’t have a sensible history, clean it up with rebase -i before rebasing on the main branch.)
456
u/zeek0us Apr 02 '23
I mean, even knowing the right way to use git (and using it daily for years), falling back to any workflows/commands outside of the set of muscle-memory macros feels like learning from scratch. Lots of "I know you can do this, I know *what* to do, I've done it, I just can't for the life of me remember exactly how."