Git doesn't have the concept of "main is special", but at least tools like Gitlab have protected branches to stop you screwing up too much. Some concept of "parent" and "child" branches would actually be pretty interesting. You do have to support multiple "parent" branches though for long term support branches.
Git Branches: Intuition and Reality
31–40 of 281 posts
Re: Git Branches: Intuition and Reality
#32I cannot be the only one that gets away with only knowing: git pull git merge x git checkout [-b] foo git commit git push
protip: If you want to switch branch you can now use "git switch [-c] foo". If you want to restore files you can do "git restore .". Basically you can stop using checkout. *edit*: fixed switch branch creation parameter.
I will keep using them so I can keep using old software. How new is it? Does ubuntu or debian have it?
Re: Git Branches: Intuition and Reality
#33You can optionally include the base commit when you send out “patches” to a mailing list.[2] Because it might not have been obvious that you based your changes on:
- The latest release
- The main development branch
- Some integration branch (probably an error)
You also need to keep the “base” in mind when you use `git range-diff` because that tool takes two ranges lik `main..previous` and `main..current`. And sometimes you can rely on just using `main..` and letting Git figure it out but in my experience passing an explicit value sometimes works better.
`git range-diff` is a super-cool but perhaps niche tool. But you basically have to use it on review round number 2 and higher when you are sending changes to the Git project.
[1] This has been discussed before and there was a patch series that implemented it. But that was basically a POC and done in the spirit of “this is useless IMO but here’s how you could do it”... and the implementation didn’t factor in all the shenanigans that you can do with `reset` and `rebase` so it couldn’t have been merged as-is. (Although to be fair: the bar was not set to work perfectly with any kind of branch reset etc., which I suspect is impossible in any case.)
[2] Patches after all are just commit messages plus the patches themselves and don’t tell you what they are based on.
Re: Git Branches: Intuition and Reality
#34I cannot be the only one that gets away with only knowing: git pull git merge x git checkout [-b] foo git commit git push
For me, git becomes unintelligible when there's a crazy train-track map of branching and merging. So I usually do whatever I can to keep a single straight-line master history. I branch off for a task, then after a while my branch isn't joined at the tip of master. So I rebase locally until it is. Then when the PR happens, master gets my changes added to the top, with no extra noise from merge commits. Even if the loc…
Re: Git Branches: Intuition and Reality
#35I cannot be the only one that gets away with only knowing: git pull git merge x git checkout [-b] foo git commit git push
Re: Git Branches: Intuition and Reality
#36A lot of things in git are just pointers to commits, and then the git implementation handles them under the covers in some way that usually makes sense but not always. One example that also bites people: moving files isn't stored in git - if you move files (even with `git mv`) and create a new commit, the moves aren't stored, but this is reconstructed later by the client based on similarity, which comes from the diff…
Re: Git Branches: Intuition and Reality
#37That's an excellent explanation. > “Wrong” models can be super useful. This is used in usability and UX design a lot. Affording mental models that don't reflect the actual code, happens all the time.
Re: Git Branches: Intuition and Reality
#38Earlier quoted context omitted.
protip: If you want to switch branch you can now use "git switch [-c] foo". If you want to restore files you can do "git restore .". Basically you can stop using checkout. *edit*: fixed switch branch creation parameter.
"THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE." I will keep using them so I can keep using old software. How new is it? Does ubuntu or debian have it?
Re: Git Branches: Intuition and Reality
#39I'm forever grateful for one of my early internships, where a guy from GitHub visited the office and gave us a one day workshop on Git. He started from the internals and explained how Git models your codebase. (He's also the one who introduced me to the idea of plumbing vs. porcelain.) Then once we had a common language, teaching the porcelain was a matter of starting from the plumbing and working upwards, rather than the other way around.
Another invaluable resource in learning Git is this interactive tutorial [0], which renders a tree diagram of start state and desired end state and makes you write the commands (for which there are often many options!) to get to that end state. This reinforces the idea that the best way of planning Git commands is to first visualize the end state you want, and then reason about how to get there.
Also: RTFM! Not just once. Go back to it. You'll learn something new every time. The docs [1] are really good.
Re: Git Branches: Intuition and Reality
#40We're teaching Git wrong. Most of the common confusion is due to people learning from the porcelain down to the plumbing, when it should be the other way around. If you limit your mental model to the plumbing, there's generally only one outcome that you want, but there are a dozen ways to get there from the porcelain. You can choose whichever one you prefer. But if you start from one of those dozen ways, they could e…