this post was submitted on 25 Jun 2023
31 points (100.0% liked)

Git

2632 readers
14 users here now

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Resources

Rules

  1. Follow programming.dev rules
  2. Be excellent to each other, no hostility towards users for any reason
  3. No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 1 year ago
MODERATORS
 

I basically only use git merge like Theo from T3 stack. git rebase rewrites your commit history, so I feel there's too much risk to rewriting something you didn't intend to. With merge, every commit is a real state the code was in.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 29 points 1 year ago (3 children)

It's not rebase vs merge, it's rebase AND merge.

Commit your changes into logical commits as you go.

Then just before submitting a pull request, review your own code. That includes reviewing your own commits too, not just the code diff.

Use rebase to:

  • Swap commits so that related changes are together
  • Edit your commit messages if you find a mistake or now have a better idea of what to put in your messages
  • Drop any useless commits that you just end up reverting later
  • Squash any two commits together where the first was the meat of desired change and the second was the one thing that you forgot to add to that commit so you immediately followed it up with another commit for that one missing thing.

Then, and only then, after you have reviewed your own code and used rebase to make the git history easier to read (and thus make it easier to review), then you can submit a pull request.

[–] [email protected] 7 points 1 year ago

Yeah, doing a git rebase -i --autosquash prior to opening a PR is good practice. (Also folks should look into autosquash if they haven't heard of it.)

[–] [email protected] 6 points 1 year ago

love this approach and it's what I usually use. I also don't rebase after opening a PR (GitHub) because force pushing ruins reviewer context in the GH UI. so after the PR is open I merge main/master in instead of rebasing.

[–] [email protected] 4 points 1 year ago

This sounds like a really good work flow. I've only started working professionally with git only few months ago when I switched jobs to gamedev (for some reason, even though I worked for three years as a pentester in cybesecurity company they literally didnt use VCS for anything), so I still don't have proper git workflow of my own, and this sounds way better. Thanks!

Before I had to start making PRs, my whole git experience on personal projects was git add . ; git commit; git push;