Tag: git

a distributed version control system that has taken over the world

  • git diff-highlight

    Diff output from git can be hard to read. Luckily there’s a nice tool bundled with git that can help us out.

    Enter diff-highlight, a little perl script found in git’s contrib directory.

    From its own documentation:

    [diff-highlight] post-processes the line-oriented diff, finds pairs of lines, and highlights the differing segments.

    diff-highlight is shipped in a default git install but it needs to be bundled and added to your $PATH. Here’s how to do it on debian:

    $ sudo make -C /usr/share/doc/git/contrib/diff-highlight
    $ sudo ln -s /usr/share/doc/git/contrib/diff-highlight/diff-highlight /usr/local/bin/

    Now you can pipe git’s diff output to to diff-highlight to get a better view of what actually changed.

    git diff | diff-highlight

    Optionally, you can configure git to use it all the time. Add the following to your ~/.gitconfig:

    [pager]
    log = diff-highlight | less
    show = diff-highlight | less
    diff = diff-highlight | less

    See the documentation for more usage tips!

  • Default git branch name

    Update:

    As of git 2.28, there’s a new configuration option and you don’t need to use the templateDir option:

    git config --global init.defaultBranch main

    Changing git’s default branch name has come up recently as an easy action we can take to update our language and remove harmful ideas from our daily usage.

    I’m concerned that this effort to change the language used is ultimately a symbolic gesture to avoid scrutiny into actual change (notably github’s push for this change and continued contracts with ICE).

    However, it’s an easy change to make.

    Let’s have a look at how to change it for new repos:

    mkdir -p ~/.config/git/template
    echo "ref: refs/head/main" > ~/.config/git/template/HEAD
    git config --global init.templateDir ~/.config/git/template

    Note that you can put this template dir anywhere you like.

    You can also set this system-wide (not just for your user) in /usr/share, but note that this might get overridden by package updates.

    echo "ref: refs/head/main" | sudo tee /usr/share/git-core/templates/HEAD

    The next time you git init, you’ll be on a branch named main.

    To change an existing repo, you can use the -m switch of git-branch:

    git checkout master
    git branch -m master main

    Push with -u to your remote if needed and update the default branch in the repo settings in the hosting platform of choice.

    It’s a relatively easy change, but don’t kid yourself that it makes any real impact. go protest, donate and sign petitions, and get out there to fix the actual problems.

  • Dotfiles

    Finally got around to updating my dotfiles to use gnu stow. I adapted ~tomasino’s makefile for use with the configs that I’m keeping with it.

    Now I just need to figure out why my ssh config doesn’t copy/symlink my config to ~/.ssh when it already exists.

  • git remotes with ssh aliases

    Did you know that ~/.ssh/config aliases work for git remotes?

    ~/.ssh/config

    Host gh
    HostName github.com
    User git
    IdentityFile ~/.ssh/gh_key

    You can now use gh:username/repo as the remote in place of git@github.com:username/repo, which is much shorter and easier to type many times!

    git clone gh:benharri/learngit

    There are many other use cases for the ssh_config file. For example, here is my config for the tilde machine for easy ssh connections.

    Host tilde
    HostName tilde.team
    User ben

    Then use ssh tilde to start a new ssh session. This also works with scp: try something like this scp file.txt tilde:workspace/. in place of scp file.txt ben@tilde.team:workspace/.

    The ssh_config file is super useful. Check man ssh_config for a full list of options!