• evmar 38 minutes ago

    My favorite "took me a long time to discover" Git tweak is to use difft for diffs:

    https://difftastic.wilfred.me.uk/

    • kibwen 21 minutes ago

      The irony here being that GitButler is a GUI for git, whereas most of these config values are for the benefit of the CLI. :P

      Since they're being too polite to shill themselves, I'll tempt HN by mentioning that GitButler is open-source and will soon be switching its underlying git support from libgit2 to gitoxide (a rewrite of libgit2 in Rust).

    • videlov 3 days ago

      > excludesfile = ~/.gitignore

      It has happened to me in the past to wonder why certain files/folders are ignored by git, only to realise that I had a global git ignore for the particular pattern.

      Not sure l’d recommend this as a good default, but perhaps others have better memory than I do.

      • zaptheimpaler 2 hours ago

        My gitignore is just a pile of things I _always_ want to ignore:

             # OS
            .DS_Store
        
             # Editors
            .vscode-server/
            .idea/
        
             # Javascript
             .npm/
             node_modules/
        
             ...more stuff per language
        
        I find it really nice to just keep all that in one place and not have to configure it per project. There's nothing too broad or situational in there that might get in the way - those kinds of things can go into the project specific .gitignores.

        There's also `git status --ignored` to check if you're missing anything.

        • codetrotter an hour ago

          My reason for having each and every common ignore in each individual repo is that on the off chance that someone else wants to contribute to any of my projects, those files are already ignored for those people too.

          And also, sometimes I work from different machines and I don’t really want to have yet another dotfile to sync between all my current and future machines.

          (Yes, I know dotfile managers exist, but I literally only care about syncing my zsh config files and one or two other dotfiles mainly so I do that with my own little shell script and basically don’t care about syncing other dotfiles.)

          • jedberg 4 minutes ago

            You don't keep your dot files in git? :)

          • dkarl 2 hours ago

            I always put IDE-specific ignores in a global gitignore since not every project gitignore has an entry for every IDE.

          • idle_zealot 3 hours ago

            It makes sense to have global defaults specific to your machine if and only if your workflow (editor, personal tooling) creates files that you don't want as a part of any project. Things like vim or emacs temp files, macOS's DS Store files, etc. This doesn't apply if your team uses standardized editor configs.

            • kyleee an hour ago

              Tangentially you can set vims temp/swap files to something like ~/.vim/tmp/ so they don’t clutter repo directories. At least that’s my pref for this annoyance/clutter

            • edoceo an hour ago

              I have to put a complete one in every project. I work with a lot of junior devs. On many occasions they're committing too much - cause they a) don't have good global config and b) are not selective about git add. A teaching opportunity but annoying to clean up.

              Just a view from the other end of the spectrum.

              • DEADB17 38 minutes ago

                https://git-scm.com/docs/git-check-ignore is useful to diagnose why a file is ignored

                • g4zj 3 hours ago

                  This option in general seems odd to me. Wouldn't all contributors to the project need to coordinate their exclusions manually this way? Am I missing something?

                  • MrJohz 2 hours ago

                    You would normally use both this and a project-specific gitignore.

                    The project-specific file is for stuff that should be shared amongst all users of a particular project. So for a Node project you might have `node_modules` in there, for a Python project you might have `.venv` and `*.pyc`. If your project uses env files, you might have a line like `.env` in there for that.

                    Meanwhile, the global gitignore is for stuff that's specific to your system. If you're on MacOS, you might have an entire for `.DS_Store`, or if you use Vim a lot you might have an entry for `*~` files (i.e. vim backup files). This is stuff that's specific to you.

                    Git can then combine the project-specific ignores (located in the project respiratory) and your user-specific ignores (located in your global gitignore file), and ignores anything that matches either case.

                    • tomjakubowski 2 hours ago

                      It's useful for bespoke developer settings. I like to keep a scratch folder in virtually every repo I work on, so I have `/tomscratch` in my global excludes file. Adding this to .gitignore in every repo I work on would just be noise for everyone else.

                      • jjayj 2 hours ago

                        Similarly, I globally exclude `*.tmp`. I can pipe logs or anything else to some `example.tmp` and never worry about checking them in.

                        • dunham 29 minutes ago

                          I've been putting a .gitignore file containing a single * inside my scratch directories. But ~/.gitignore sounds like a good idea for local things that I do in every repository.

                        • Vinnl 3 hours ago

                          I imagine it includes things like .DS_STORE.

                        • jcalvinowens 3 hours ago

                          Agreed, I don't want my checkout implicitly ignoring a file somebody else's checkout wouldn't.

                          • tremon 40 minutes ago

                            Probably not what you meant, but git checkout is not affected by .gitignore anyway. If a file is already in the repository, git will keep tracking it.

                          • npteljes 3 hours ago

                            I agree with you. In fact, I think it's better to free up "configuration" memory, and use it to store "best practice" or "process" in general. I find that convention over configuration works out better on a long run, and when switching between projects - either the developer themselves, or when parts of the team leave and others join.

                            • isaacremuant 2 hours ago

                              I disagree. If it's minimalistic and focused on your commonalities across projects in a computer, such as VScode stuff which shouldn't be committed to a general repo, I think it's the right and unobtrusive choice.

                            • larusso 3 hours ago

                              Good stuff here. But I don‘t like the auto pruning suggestion as a reasonable global default. Or at least this shows that users who really see this as useful see no real difference between git and let’s say SVN. The whole idea is that the system is distributed and that you don‘t follow blind another upstream. But I grant the fact that most projects are not developed like the Linux kernel for which git was created. But there is another issue. I personally like the fact that I keep a history of old branches etc. This can also save me if I or another person in the team deletes a branch by accident. I assume that pruning would maybe not delete the objects right away. Need to check that.

                              What would actually happen if I have a branch under development and it gets deleted from remote? Will it remove locally for me then? I guess only when my local head is equal to what remote pointed to.

                              • T-Winsnes 2 hours ago

                                I had the same thought, I got an alias set up in my ~/.gitconfig to clean up branches that gets deleted from remote when I'm ready

                                `gone = !git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D`

                                • juped 2 hours ago

                                  Because Git is distributed, there's no "a branch" foo or whatever; that's a very pointedly centralized-logic, non-DVCS way to treat Git. If Alice has a head named "foo", Bob can fetch Alice as a remote and get a remote-tracking head "alice/foo", which has no bearing on any head named "foo" Bob has; it's just a view of Alice's state.

                                  You can see why you'd want to prune these on fetch, if you want your refs/remotes/alice state to mirror Alice's state; this means removing "alice/foo" if "foo" on Alice is removed. You also might not want to, that's fine. But if you use git fetch as though Git were a DVCS, this is exactly the natural behavior; it's only when you imagine Git is centralized that it starts seeming strange.

                                  So the answer to your final question is "this is not how distributed VCSes work".

                                  (Just don't ask about tags. Ugh, what a nightmare! To be fair, the idea is that you don't go around fetching tags.)

                                • do_not_redeem 4 hours ago
                                  • schacon 3 days ago

                                    Curious what I might have missed that you all put in your `~/.gitconfig`

                                    • tremon 27 minutes ago

                                      This is my global gitconfig (minus personal things like user.email etc):

                                        [core]
                                             pager =
                                        [pull]
                                             ff = only
                                      
                                      I don't want git to start a merge without my explicit request, hence the ff-only on git pull. Similarly, opening a pager without me explicitly asking for it is an antipattern and I can't stand tools that do so by default. My terminal has scrollback history TYVM.

                                        [push]
                                             default = upstream
                                      
                                      I think this is the default now anyway, but I don't want git assuming anything about remote-local branch relationships.

                                        [alias]
                                             tlog = log --graph --oneline
                                      
                                      Simple git tree-log shorthand.

                                        [status]
                                             showStash = true
                                        [stash]
                                             showPatch = true
                                      
                                      I always tend to forget when I stashed something, so I need the explicit reminder. The second one makes git stash more like git show.
                                      • wahnfrieden 4 hours ago

                                        .DS_Store

                                        *.swp

                                        • infogulch 4 hours ago

                                          That's .gitignore. GP is asking about what you have in your .gitconfig.

                                          • Retr0id an hour ago

                                            You can however put those in your global `core.excludesfile` path as defined in .gitconfig

                                      • juped an hour ago

                                        Wow, never autopush all your tags. What a terrible idea! Once a tag escapes into the wild, it's so hard to ever get rid of it. Pushing a tag should require two people turning keys simultaneously or something, honestly.

                                        zdiff3 is also NOT some kind of generic improvement over diff3, like swapping diff algorithms is sorta a generic improvement. It behaves very differently; if you have

                                            [original]
                                            this is a line
                                        
                                            [left branch]
                                            This is a line.
                                            This is a second line.
                                        
                                            [right branch]
                                            This is a line.
                                            This is another line.
                                        
                                        then diff3 shows

                                            <<<<<<<
                                            This is a line.
                                            This is a second line.
                                            |||||||
                                            this is a line
                                            =======
                                            This is a line.
                                            This is another line.
                                            >>>>>>>
                                        
                                        while zdiff3 modifies this in a very matter-of-personal-taste way to:

                                            This is a line.
                                            <<<<<<<
                                            This is a second line.
                                            |||||||
                                            this is a line
                                            =======
                                            This is another line.
                                            >>>>>>>
                                        
                                        This is incredibly bizarre to my eye, but some prefer how it's already "partially resolved" for them. But it's hardly something to swap in thoughtlessly for the other!
                                        • hylaride 5 minutes ago

                                          Agreed. If you're using tags for anything other than final releases off of main/master (or other release branches that are supposed to be permanent), you've gone down a very bad path.

                                        • albingroen 4 hours ago

                                          I’d bet my money on the GitButler team. They’re experts in a small market and I think they’ll do something great. I don’t think their current product is it, but I think they’ll do something great.

                                          • trandingstar 21 minutes ago

                                            Trandingstar

                                            • mattmanser 3 hours ago

                                              This was posted already earlier today, lots of comments on the other thread:

                                              https://news.ycombinator.com/item?id=43169435

                                              • westurner 24 minutes ago

                                                skwp/git-workflows-book > .gitconfig appendix: https://github.com/skwp/git-workflows-book?tab=readme-ov-fil... :

                                                  [alias]
                                                  unstage = reset HEAD              # remove files from index (tracking)
                                                  uncommit = reset --soft HEAD^     # go back before last commit, with files in uncommitted state
                                                
                                                https://learngitbranching.js.org/

                                                charmbracelet/git-lfs-transfer: https://github.com/charmbracelet/git-lfs-transfer

                                                jj-vcs/jj: https://github.com/jj-vcs/jj

                                                • MzHN 3 days ago

                                                  Might be worth mentioning that fsmonitor is Windows and Mac OS only.

                                                  Also I wish GitHub and GitLab had colorMoved.