DEV Community

Discussion on: Which git commands do you struggle with?

Collapse
 
alaindet profile image
Alain D'Ettorre

Rebasing: concept is clear, I can do a dead simple rebase, but rebasing in general is a struggle, so much that I almost always end up merging. My bad, I know.

Collapse
 
jankapunkt profile image
Jan Küster

Rebase is so underrated but also so hard to grasp, which is why also often use merge or squash merges.

Collapse
 
isaacdlyman profile image
Isaac Lyman

I support you, it's okay to merge. (I also don't really understand rebase)

Collapse
 
csgeek profile image
csgeek

rebase just pulls in the changes from a branch and keeps your changes on top. if you do a -i with rebase it lets you squash, reorder commits and a bunch of other things. It's very powerful IMO.

Thread Thread
 
isaacdlyman profile image
Isaac Lyman

So is it the equivalent of making a fresh branch off of the other branch, then cherry-picking all your commits back onto it? E.g.:

git checkout working-branch
git commit -m "My commit"
git rebase main
Enter fullscreen mode Exit fullscreen mode

==

git checkout working-branch
git commit -m "My commit"
git checkout main
git checkout -b new-working-branch
git cherry-pick {commit hash of "My commit"}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
csgeek profile image
csgeek

Sure, but if you have 15 commits on your branch you'd have to cherry-pick all 15s. rebase is much easier to use, but it is equivalent if you want to use that.

It has other features (squash, reorder, etc) which are really handy that I mentioned earlier though for the standard behavior that is equivalent.

Collapse
 
c24w profile image
Chris Watson • Edited

I can handle interactive rebasing, but it does sometimes get you in a muddle. The thing is, you have to solve all the same conflicts as a merge, just not all-at-once and it keeps the history cleaner.