this post was submitted on 06 Nov 2023
23 points (100.0% liked)

Git

2910 readers
1 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
top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 7 points 1 year ago (1 children)

Great read. Rebase is such a powerful tool. I do think that git rebase -I derserved to be its own command. A lot of people I teach debasing to get confused by the difference between rebasing onto a ref, and pruning a branch

[–] technom 1 points 1 year ago

Git rebasing is extremely confusing. I say this as someone who does it on a daily basis. Rebasing takes significant effort to teach. The fundamental concepts are different from regular git use - it makes an abrupt jump from snapshot model to diff model.

A large section of developers simply don't reach that level of proficiency in their entire career - instead depending on the organization's expert for those tasks.

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

Good article

[–] lysdexic 1 points 1 year ago* (last edited 1 year ago)

I'm not sure the author of this blog post is experienced with git rebase. I'm by no means an experienced git user, and to me the single most useful thing about git rebase is reordering commits in a local branch. This means I can commit some code in a local branch, continue working on stuff, and later move commits around to peel off PRs out of a feature branch. However, the author makes zero mentions to this feature in the blog post.

To illustrate how useful git rebase is, picture yourself working on a feature branch as part of your work on an issue. Suddenly you stumble upon something that you need to fix to unblock your work on that feature, but it's not directly related to your issue. You can stash your changes, create a new feature branch, fix the bug, post a PR, expect it to be merged, and afterwards rebase your feature branch onto mainline.

That's ok, but very time consuming.

You can instead use git rebase. Just go straight ahead and commit your code straight away in your feature branch and continue working. After you're done working on your feature, you run git rebase to reorder your commits so that the ad-hoc fix is the first commit in your feature branch, and you post a PR for that fix alone, and once it's merged you already have all your other changes lined up to be pushed as well.

Another usecase I follow often is posting an ad-hoc commit to simplify working on a issue. This means adding logging, forcing a flag, commenting out code, etc. I commit this message with commit messages that make it clear that this code is not to be pushed, and follow a convention that commit hooks can pickup as guardrail. From that point onward I just work on the feature until I'm done, and when I'm ready to post a PR I simply crack open git rebase, reorder the commits to move the ad-hoc commit to feature as the very last one, drop it, and done.

[–] zygo_histo_morpheus 1 points 1 year ago* (last edited 1 year ago)

I was curious about why people would run git push --force on a shared branch. Some reasons people gave were:

  • they’re working on a collaborative feature branch, and the feature branch needs to be rebased onto main. The idea here is that you’re just really careful about coordinating the rebase so nothing gets lost.

A safer solution would be to make a new branch and do the rebase on it instead, that way the shared branch won't be impacted. You might still lose changes if they're pushed after merging to main but that's not really rebases fault. You can always cherry pick or something then from the original un-rebased branch (hopefully without any merge issues...)