by trevor-e · 7y ago · 0 comments
- Always pull w/ rebase for the current branch.
- Always merge other branches into your current branch, eg master -> feature.
- Always stage individual chunks of code one at a time to make sure I'm committing the right stuff.
- Always squash feature branches into a single commit when merging back.
- Stash changes if needed when switching branches.
- Cherry-pick one-off commits if needed.
- Append a previous commit that I haven't pushed yet if I happened to forget something.
- For complicated merge conflicts I switch to Visual Studio Code which also has a great GUI.
I think this covers 99% of the stuff I encounter in my day-to-day.
For the sake of your future sanity (and your coworkers'), please stop trying to rewrite history for the sake of aesthetics. The defaults are what they are for a reason.
Additionally, if I do the aforementioned git pull, I have no way of turning the commit message into an informative one because I have no information regarding the commits. Is there a way to actually know it beforehand to turn that message into a meaningful one? If so, how would you do it? If it is possible, should I just have a list of all the commits' message in that one merge commit? Regardless, I see lots of "Merge branch ... of ... into ..." commit messages and they are not useful to me at all. Why do you think people keep doing it?
I have used this in projects and it worked great for the whole team for a long time. You can of course do something else which can work for you and your team.
Without using either flag rebase should update the commit date and preserve the author date.
If by rebase you meant GitHub's rebase merge option I think you're out of luck :-/
This is really the only command I do by hand because I can't find the equivalent (yet, probably haven't looked hard enough) in Fork.
edit: oh I think I misread what you said. When working on a feature branch I don't care too much about the branch history since I know it's eventually being squashed back into a single commit.
Anything works when both of those prerequisites are met. You're unlikely to do the bad things that force more advanced needs.
Everyone should do this. Think back to how much time you've lost due to git problems. It'd probably take less time to learn it correctly up-front, and never have to deal with them ever again.
It seems to have next to zero functionality. What is the point of it? What you you use it for, other than commit, push?
I use Sublime Merge, but no Git GUI I've used comes close to tortoisehg for mercurial. Tortoisehg is actually superior to and a comprehensive replacement for the command line. I wish something like it existed for git, if not for me then for the newbie-ish people I need to instruct on project workflows.
Find a _simple_ git workflow, document it in a style guide, stick to it. Git doesn't have to be complicated.
I also don't bother appending (though my GUI lets me undo the last commit if I haven't pushed which is maybe the same thing.)
Most developers get way too fancy with Git and screw something up. I use GitHub Desktop and rarely touch the command line for Git. It has a great UI for being able to just pop over and see my current changes, and easily commit just a line or two from them to make commits other people can understand.
- needing to memorize branch names for easy use: there is tab completion for this;
- differences between staged and pushed commits: I'm not sure what you refer here. the closest concept to the "stage" term is "staged changes". this is by design; the idea is that while one applies changes within a single commit, some are definitive, some are evolving; for this workflow, it's very convenient. if one doesn't want, they can just add all and commit (preferrably, with a single alias ;-)).
The "most extensive" Git UX problem is possibly the excess of functionality given to the `checkout` command, which in fact is being split.
(I don't imply that Git UX is good, though)
It absolutely is. The whole "branch" paradigm evokes topology. The visual structure of the thing you're working with ought to be made clear to you, the user.
If a GUI has trouble when the workflow deviates from normalcy, it's just not powerful enough.
That being said, there will always be users who prefer the command line, and that's totally fine.
- visualise the project in its current state which may spread across several feature branches all coming in and out of master
- code preview (hugely valuable) across one or more files
- see your branches
- see your stashes
- remotes, etc
- all of the above across multiple, simultaneous, projects.
Large projects can be difficult to manage if you don't have context and oversight, which is harder to obtain from the CLI.
Of course we can get this information from the prompt but it is much more difficult to get the information in an easier-to-consume fashion.
I don't know why, but I've always felt uncomfortable using git in a GUI, but I know a lot of people who love it.
For some reason, anytime I try to use a GUI, I don't feel like I'm really doing git, if that makes any sense. Also, I've personally never felt the need to see the branches visually. And if I do get the itch to 'see' them, nothing a quick
git log --oneline --graph
cant fix!* I almost always just do a regular merge to master (rather than squash).
* I use GitKraken which (in the pro version) has a great merge tool.
A lot of people seem to want "clean history" so just I'd just like to put it out there that it's not really necessary (there's nothing wrong with it, of course), and regular merges work just fine. In my experience, the two main reasons I look at git history are:
(1) Checking when a feature was done and what releases it got into
(2) Finding out why a particular line of code exists (blame)
For (1), with software with numbered releases, you end up following the branches anyway. Having the individual commits from feature branches makes you scroll more, but it doesn't make it any harder to follow. If you really don't like seeing them, you can hide anything but merge commits.
Even simpler, if all you care about is whether a given feature branch is done (merged) or not, that's easy to see and the same as a squash-merge workflow.
With continuously-deployed ("cloud") services, things are even simpler - you start at the hash currently deployed and go backwards. It makes no difference if there's one branch or many feature branches (other than scrolling past more granularity).
For (2), the greater granularity from individual commits is generally useful (at least provided that each commit has a ticket number and useful description), and squashing erases this detail.
Also, a nice thing is if you end up merging the same branch to multiple places (master and a release branch, for example) it's obvious what happened by looking at the tree. Contrast to if you cherry pick a squash merge commit, the only way to see that is to read both commits and realize they're the same -- and this is much less obvious if there's other commits between them.
Basically, squash merging doesn't help with either of these, and in fact actively hinders (2).
My team has been doing this for a few years, and I'm not even sure if it was a conscious decision to merge this way (or not do squash merge) but we've had no reason to change. It does depend on every commit being well-formed, but this is pretty easy to ensure in a paid team that works on this every day (whereas with open source I'm not sure it'd work well).
Anyway, like many things in git, there's more than one way to do it, and there's no clear "right" or "wrong" way.
git commit --fixup 6138D3A
git rebase --autosquash --interactive origin/master
to keep a clean history of cohesive commits. Rarely do I change _everything_ required for an objective in one go, I still like to commit as I work, I just like the finished product to _seem_ like I did it in one go, for future maintainers' sake.And I rebase to catch up with upstream, I can't stand having intermediate merge commits in my history and rebasing lets you resolve conflicts as they're introduced, instead of an all-at-once at the end.
[alias]
fix = "!_() { c=$(git rev-parse $1) && git commit --fixup $c && if grep -qv \"No local changes\" <<<$(git stash); then s=1; fi; git -c core.editor=cat rebase -i --autosquash $c~; if [[ -n "$s" ]]; then git stash pop; fi; }; _"
The workflow becomes: $ git add ... # stage the changes you want to apply to 6138d3a
$ git fix 6138d3a