Live data from Hacker News

Better Git configuration

blog.scottnonnenberg.com

41–50 of 66 posts

Re: Better Git configuration

#42

I'm going through my gitconfig and I'm realizing there's ALL THESE really nice shortcut I literally never use.

Same, it's hard to break one's finger memory when you're used to e.g. typing `--force --no-verify` in full all the time. Although imo those should always be typed out in full.

Re: Better Git configuration

#43
One thing I like to do is alter the coloring as an aide for `git status` which is giving "changed" a yellow as an intermediary color

    [color "status"]
            added = green
            changed = yellow bold
            untracked = red bold

Re: Better Git configuration

#44

I have a ridiculous "vim style" alias setup: https://github.com/myfreeweb/dotfiles/blob/4eb052cc54f9edcc8... So I can just e.g. type "g ws" to tell [g]it to give me the [w]orking tree [s]tatus. Seeing people actually type "git status" is just painful.

That's impressive. Together with (neo)vim as $GIT_EDITOR I can see that being really nice to use.

Now you could decide to systematize the "grammar" of your shortcuts somehow, and, well... it's definitely an idea people have had before. ;)

https://magit.vc/screenshots/popup-diff.png

Not an Emacs fanboy, by any means: I use Spacemacs. Magit is objectively excellent, though.

Re: Better Git configuration

#45
I have a dedicated Git tmux tab for every repo I'm working on, in that tab I use a git shell. Initiated by this bash function:

    # A nice shell prompt for inside git repostories
    # Shows a short status of the repository in the prompt
    # Adds an alias `g=git` and makes autocomplete work
    gitprompt() {

        __color_bold_blue='\[$(tput bold)\]\[$(tput setaf 4)\]'
        __color_white='\[$(tput sgr0)\]'

        export GIT_PS1_SHOWDIRTYSTATE=true;
        export GIT_PS1_SHOWSTASHSTATE=true;
        export GIT_PS1_SHOWUNTRACKEDFILES=true;
        export GIT_PS1_SHOWUPSTREAM="auto";
        export GIT_PS1_SHOWCOLORHINTS=true;
        . /usr/lib/git-core/git-sh-prompt;

        local ps1_start="$__color_bold_blue\w"
        local ps1_end="$__color_bold_blue \\$ $__color_white"
        local git_string=" (%s$__color_bold_blue)"

        export PROMPT_COMMAND="__git_ps1 \"$ps1_start\" \"$ps1_end\" \"$git_string\""

        # Short alias for git stuff
        alias g=git

        # Make autocomplete also work fo the `g` alias
        eval $(complete -p git | sed 's/git$/g/g')

    }
So I have this in my `.bashrc` and when I want my bash to get a handy Git prompt I type `gitprompt`.

You do need the file `git-sh-prompt` which should come with git, for me it's located in `/usr/lib/git-core/git-sh-prompt`. It's also available here:

https://github.com/git/git/blob/master/contrib/completion/gi...

Re: Better Git configuration

#47
post #7

Oddly, the author recommends signing commits, yet uses only fast-forward merges. Little do they know that signed commits necessarily can not be resolved as fast-forwards in a merge situation, since that would require changing the signatures! Rebasing is the answer, but that will of course re-sign every commit with your key. In a shared repository, I prefer creating "useless" merge commits to changing other peoples si…

Perhaps I misunderstand you, but a fast forward merge isn't really a merge (there is no merge commit) and by definition doesn't change any commits. So it doesn’t require changing any commits, and therefore no signatures need changing either.

Is there some other part of a workflow that you're inferring here that will need changing commits?

Re: Better Git configuration

#48
This references my Git Horror Story article from 2012. Which is fine, but note that git has evolved a lot since then, and you should also seek out some of its more modern conveniences (this thread's article mentions a number of them). I've been telling myself I'll update this article for the past few years. I'll get to it eventually.

As an alternative to git's aliases: if you're sick of typing `git' all the time, feel free to adapt this little script to suit your needs (allowing you to type e.g. `a' instead of `git add' and such, with tab completion):

  https://gitlab.com/mikegerwitz/git-shortmaps

Re: Better Git configuration

#50

When I want/need to customize this much, I tend to think poorly of the tool.

I'm guessing you don't like Vim or EMACS then? Or the command line in general?

Most of the development tools I use on a regular basis tend to be extremely customizable, and I regard that as a Good Thing.

Post reply on HN