this post was submitted on 04 Apr 2024
1113 points (98.1% liked)

Programmer Humor

19817 readers
58 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 8 points 8 months ago (4 children)

Anyone mind explaining to me how git rebase is worth the effort?

git merge has it's own issues but I just don't see any benefit to rebase over it.

[–] [email protected] 17 points 8 months ago* (last edited 8 months ago) (1 children)

I use interactive rebases to clean up the history of messy branches so they can be reviewed commit by commit, with each commit representing one logical unit or type of change.

Mind you, getting those wrong is a quick way to making commits disappear into nothingness. Still useful if you're careful. (Or you can just create a second temporary branch you can fall back onto of you need up your first once.)

[–] [email protected] 3 points 8 months ago (1 children)

This 100%. I hate getting added to a PR for review with testing commits in the history, and I'm expected to clean those up before merging into main.

[–] [email protected] 2 points 8 months ago (1 children)

I feel like squash and merge on GitHub/GitLab is nicer for that anyway though, it makes the main branch so much cleaner automatically

[–] [email protected] 1 points 8 months ago

If you're using "trunk-based development" (everything is a PR branch or in main), this works great.

If you're using GitFlow, it can make PRs between the major prod/dev/staging branches super messy. It would be nice if GitHub would let you define which merge strategies are allowed per-branch, but that's not a thing (AFAIK). So you're probably better off not squashing in this situation.

[–] [email protected] 7 points 8 months ago (2 children)

Well, rebase allows you to resolve the same conflict ten times in a row instead of doing it once. How cool is that?

[–] [email protected] 4 points 8 months ago (1 children)
[–] [email protected] 1 points 8 months ago

Why would I ruin all the fun?

[–] [email protected] 0 points 8 months ago (1 children)
[–] [email protected] 2 points 8 months ago (1 children)

Doesn't this defeat the purpose, may as well merge then no?

[–] [email protected] 1 points 8 months ago

Do not merge your unfinished stuff into main.

I don't like merging main into my branch because I don't understand git, and I feel like that can make a confusing history.

[–] [email protected] 4 points 8 months ago

Only before you collaborate with anyone else. After that, don't ever use rebase, or they'll get an error, and will have to overwrite their local history with the one you've rewritten.

[–] [email protected] 3 points 8 months ago

The way I structure my commits, it is usually (but not always) easier and more reliable for me to replay my commits one at a time on top of the main branch and see how each relatively small change needs to be adapted in isolation--running the full test suite at each step to verify that my changes were correct--than to be presented with a slew of changes all at once that result from marrying all of my changes with all of the changes made to the main branch at once. So I generally start by attempting a rebase and fall back to a merge if that ends up creating more problems than it solves.