While everyone is here considering their life choices (at least as far as they relate to ~/.gitconfig), highly recommend delta [1] as a companion to the git cli.
After using delta for a while, I'm going back to the regular diff view... it's not that it isn't good, but I'm constantly copying diffs (yes, I know I can generate patches) and the pretty output breaks that workflow.
Also, when your terminal is a bit small it's a bit hard to see things. But it's really good software, I recommend anyone who's reading to give it a try.
I really wanted to add this (I linked it in the last paragraph) but I really wanted to keep the recommendations globally applicable in vanilla git. Delta is awesome though.
Do your aliases even save you any keystrokes? Most shells support auto complete, and you still have to type "git" unless you have a shell alias for it.
I guess what I'm git-ing at is a truly efficient alias would be embedded in the shell. For a while I had "gsno = git status --uno" although it's been so long since I used it, I forget what the options even did. Somehow I get by with only stock commands.
Another helpful alias I used to use was ctrl-space, I had aliased for 'make'. Somehow I liked it because you can almost gesture it with slamming both hands down simultaneously.
Shortened aliases come from cvs/svn land, sorting tags by a logical manner, adding some extra archive types for "git archive", making it so git log always shows my local time zone, pull will never do a non-ff merge, make it so Git doesn't complain about repositories in places it doesn't like, turning off an annoying message about a detached HEAD state, and shut git up about the default branch.
I agree with the recommendation to use (z)diff3. I think the article massively understates the case! Three way diff makes it possible to resolve some conflicts that are literally impossible to resolve without it. Why impossible? Because with default style adding conflicting things at the same place is indistinguishable from removing the same things at the same place. You need to be able to see the base to determine that.
I also use that color.diff.whitespace "red reverse" and along with it diff.wsErrorHighlight all. I recall needing to set both in the past but in trying to find out why that might have been superseded by only needing the latter. I'm not quite sure.
Mine is here [1], I basically had all of these set already (other than column ui which I don't like), but I suspect that's just because I've probably previously read nice posts by Scott and others talking about them.
Maybe trading alias tips is another useful thing to do though, hence sharing the link.
On github you can add the ssh key for authentication but also for signing. Unfortunately you have to add the key twice but once you've done it, you get rid of the `unverified` label within a commit.
> Personally, I think the default behavior of Git should be to make your remote references as close to what is on the remote as possible. Prune stuff that’s gone, etc.
Yikes, no. Remote junk disappears all the time, and you never know when you'll have to recover something. Old versions of GitHub pull requests, in particular, tend to be garbage collected at the backend rapidly. It's a semi-regular occurrence for me that I have to dig through reflog to get to early work that everything else has forgotten about.
Just in general, don't delete stuff you don't know you don't need. That's just data robustness 101. nothing to do with git. Deletions should be as manual as possible, and generally done following a backup.
I really wish they'd update the default config once there's consensus that something new is optimal. I'm wary of even adding the config settings in this article in case things change in the future and I continue oblivious with a now dated setup.
How much of this is for a noob like me that just uses vscode? I hardly ever see the git command line, and when I do see it, its trouble beyond what anybody can fix...
VSCode git interface is actually pretty powerful, 99.9% of the git actions I do are already covered there, including merging, stashing, tagging, getting output from the git hooks...
However changing the diff algorithm is still a nice one, both for solving conflicts and to avoid the ocassional bad automated merges (the latter is scarier as you don't even know you pushed something wrong).
I wouldn't like to be this kind of person, but, in the case of git, the best you can do you is forcing yourself little by little to use the Git CLI. It's far from being beginner friendly, but it shows the things the way the really are. GUI git tools hide things under their hood, which is ok for most cases but when you need a little more complex thing you are limited to their capabilities.
I have something almost identical, except for the `—-graph` part. That way I have the flexibility to get either the linear view or the graph view by adding that single flag.
Forces pushes are dangerous enough as it is, so I'm mystified on why git doesn't insist you know the state of upstream before running it.
Sadly you can't make it the default, so I resort to:
[alias]
force-push = push --force-with-lease
As for the article, I must the the weird one because I prefer most of the settings are they are or don't care. Even some of those designated as "clearly better" don't look to me.
It's unfortunat that --force-with-lease was given such a long name compared to the strictly more dangerous --force. And yes, it would be great if we could configure --force to behave like --force-with-lease - it's not like original --force behavior is ever desirable for human operators.
That was a useful read. I'd been frustrated by `merge.conflictstyle = diff3` so I'm glad I learned about `zdiff3`.
I also discovered `fetch.prune` and `pull.autoSetupRemote` which will slightly enhance my workflow.
My only disagreement is with the diff prefixes. I prefer to display one path starting with ".", so that I can double-click it and paste it. So I don't want contextual prefixes, I'll keep my `diff.dstPrefix = ./`.
I strongly disagree. Publishing a new branch on the remote should be an explicit operation. And git push will already tell you the command you need to run so it isn't an issue with having to remember another random command.
Nit for schacon: in the "Listing branches" section, you say branch.sort + column.ui and talk about these as first/second options, but the commands are in the opposite order so it reads a little confusingly.
Wow this is neat. I never really bothered to deep-dive into my git configuration, but some of these are really cool.
The diff changes are awesome, and I always wondered why there isn't a global .gitignore file in the first place, seeing that every .gitignore file basically has (mostly) the same content
There's also an ongoing effort among creators to not pollute the home directory with too many hidden files. Instead, as the blog post mentions, there exist .config/git/ignore which I think is a more scalable approach in the long run. Especially looking at the number of tools and utilities requiring one or several config files.
One of the coolest things I've learned about recently is `.git/info/exclude`. It allows you to ignore files in the local repo without modifying the repo's .gitignore
Very useful if you want to add your own .envrc or shell.nix to a repo.
I'm curious what you mean. I've been practicing trunk based development since 2011[0] and all of these config settings help that flow. Arguably you don't want the rebase thing, but otherwise I can't imagine what you think here would not apply.
> updating the default value. I wish Git had some taste here, but they don't
So author has no preference, but git does not have a good taste here, for not breaking backward compatibility. Typical passive agresive bullshit!
I think "main" is not inclusive enough, we should use something like "non-specific-but-strong-branch". Or something that includes even stronger message. And change it every year (or month). It could be automated using github actions on all existing repos!
Also please rename "git" command, it is very insensitive word!!!
You've no idea how much real social change has been brought about, when Git changed its default branch from master to main. Pardon me, I'm tearing up right now.
Nobody is stopping you from using master, you can do whatever you want. The author even recognizes that very clearly in the text.
You can name all your default branches `megazord`. Hell, you can fork git, call it "gitzord" and enforce your `megazord` branch as The Correct Main Branch Name for every user. Feels good to be free, doesn't it?
Most of the items in this list were introduced more recently (a lot from '22) and are definite quality of life improvements. But sure, the core of Git remains mostly unchanged - the 'porcelain', if you will - although the one major change is that they're changing the default hashing algorithm (I'm not sure if this has been done yet, I know it was decided upon in 2018).
jelder|1 year ago
schacon|1 year ago
Now I want to do: `git to-da-choppa`
sedatk|1 year ago
_kb|1 year ago
[1]: https://dandavison.github.io/delta/
leonheld|1 year ago
Also, when your terminal is a bit small it's a bit hard to see things. But it's really good software, I recommend anyone who's reading to give it a try.
mplanchard|1 year ago
Looks like there are also instructions in the docs for using it with vscode
schacon|1 year ago
chungy|1 year ago
gosub100|1 year ago
I guess what I'm git-ing at is a truly efficient alias would be embedded in the shell. For a while I had "gsno = git status --uno" although it's been so long since I used it, I forget what the options even did. Somehow I get by with only stock commands.
Another helpful alias I used to use was ctrl-space, I had aliased for 'make'. Somehow I liked it because you can almost gesture it with slamming both hands down simultaneously.
chungy|1 year ago
tome|1 year ago
I wrote up more here: https://stackoverflow.com/a/63739655/997606
I also wrote up how to use diff3 style to make resolving rebase (or merge) conflicts a mechanical procedure: https://h2.jaguarpaw.co.uk/posts/git-rebase-conflicts/
conaclos|1 year ago
schacon|1 year ago
opello|1 year ago
qbonnard|1 year ago
[0] https://news.ycombinator.com/item?id=39400352
JulianWasTaken|1 year ago
Maybe trading alias tips is another useful thing to do though, hence sharing the link.
[1]: https://github.com/Julian/dotfiles/blob/main/.config/git/con...
sandreas|1 year ago
ajross|1 year ago
Yikes, no. Remote junk disappears all the time, and you never know when you'll have to recover something. Old versions of GitHub pull requests, in particular, tend to be garbage collected at the backend rapidly. It's a semi-regular occurrence for me that I have to dig through reflog to get to early work that everything else has forgotten about.
Just in general, don't delete stuff you don't know you don't need. That's just data robustness 101. nothing to do with git. Deletions should be as manual as possible, and generally done following a backup.
cassepipe|1 year ago
lucasoshiro|1 year ago
oneeyedpigeon|1 year ago
(Weirdly, git doesn't seem to honour the PAGER var (which would be even better), although its man page claims it does)
betimsl|1 year ago
rowanseymour|1 year ago
neals|1 year ago
manbitesdog|1 year ago
However changing the diff algorithm is still a nice one, both for solving conflicts and to avoid the ocassional bad automated merges (the latter is scarier as you don't even know you pushed something wrong).
lucasoshiro|1 year ago
For instance, I wrote this post last year about how you can use Git as a powerful debugging tool: https://news.ycombinator.com/item?id=39877637
jbverschoor|1 year ago
Graphical diff viewers are way better anyway.
pfg_|1 year ago
jeffwass|1 year ago
schacon|1 year ago
musikele|1 year ago
alex_smart|1 year ago
rstuart4133|1 year ago
Sadly you can't make it the default, so I resort to:
As for the article, I must the the weird one because I prefer most of the settings are they are or don't care. Even some of those designated as "clearly better" don't look to me.account42|1 year ago
idoubtit|1 year ago
I also discovered `fetch.prune` and `pull.autoSetupRemote` which will slightly enhance my workflow.
My only disagreement is with the diff prefixes. I prefer to display one path starting with ".", so that I can double-click it and paste it. So I don't want contextual prefixes, I'll keep my `diff.dstPrefix = ./`.
account42|1 year ago
> [...]
> [push]
> autoSetupRemote = true
I strongly disagree. Publishing a new branch on the remote should be an explicit operation. And git push will already tell you the command you need to run so it isn't an issue with having to remember another random command.
rmccue|1 year ago
trebligdivad|1 year ago
Galanwe|1 year ago
deathanatos|1 year ago
tobyhinloopen|1 year ago
dark-star|1 year ago
The diff changes are awesome, and I always wondered why there isn't a global .gitignore file in the first place, seeing that every .gitignore file basically has (mostly) the same content
schacon|1 year ago
There's also a possible downside here in having things hidden for you but not for others since it's not in your `.gitignore` project file.
I'm honestly kind of on the fence about this one, I don't have much in that file for those reasons.
whirlwin|1 year ago
marcyb5st|1 year ago
I think it's the most readable and understandable diff.
wh33zle|1 year ago
Very useful if you want to add your own .envrc or shell.nix to a repo.
unknown|1 year ago
[deleted]
n_plus_1_acc|1 year ago
leslielurker|1 year ago
Dlooooloo|1 year ago
It's shorter, sounds nicer.
recroad|1 year ago
schacon|1 year ago
[0] https://scottchacon.com/2011/08/31/github-flow/
lylejantzi3rd|1 year ago
If these options clearly make git better, why aren't they the defaults?
Forge36|1 year ago
carlosneves|1 year ago
silvanocerza|1 year ago
My config if you'd like to steal it, also here: https://github.com/silvanocerza/dotfiles/blob/master/git/git...
Mind that you need diff-so-fancy for this work correctly. https://github.com/so-fancy/diff-so-fancy
FirmwareBurner|1 year ago
high_byte|1 year ago
uscneps|1 year ago
schacon|1 year ago
nialv7|1 year ago
thro949494i|1 year ago
> Personally, I don’t have a problem with master
> updating the default value. I wish Git had some taste here, but they don't
So author has no preference, but git does not have a good taste here, for not breaking backward compatibility. Typical passive agresive bullshit!
I think "main" is not inclusive enough, we should use something like "non-specific-but-strong-branch". Or something that includes even stronger message. And change it every year (or month). It could be automated using github actions on all existing repos!
Also please rename "git" command, it is very insensitive word!!!
randunel|1 year ago
penguin_booze|1 year ago
jaybro867|1 year ago
[deleted]
unknown|1 year ago
[deleted]
aboardRat4|1 year ago
[deleted]
becquerel|1 year ago
ahartmetz|1 year ago
matusp|1 year ago
leonheld|1 year ago
You can name all your default branches `megazord`. Hell, you can fork git, call it "gitzord" and enforce your `megazord` branch as The Correct Main Branch Name for every user. Feels good to be free, doesn't it?
And PS: I'm not from the USA ;-)
sliq|1 year ago
Cthulhu_|1 year ago