Some git aliases that I use

February 12, 2020

As a system administrator, I primarily use git not to develop my own local changes but to keep track of what's going on in projects that we (or I) use or care about, and to pull their changes into local repositories. This has caused me to put together a set of git aliases that are probably somewhat different than what programmers wind up with. For much the same reason that I periodically inventory my Firefox addons, I'm writing down my common aliases here today.

All of these are presented in the form that they would be in the '[alias]' section of .gitconfig.

  • source = remote get-url origin

    I don't always remember the URL of the upstream of my local tracking repository for something, and often I wind up want to go there to do things like look at issues, releases, or whatever.

  • plog = log @{1}..

    My most common git operation is to pull changes from upstream and look at what they are. This alias uses the reflog to theoretically show me the log for what was just pulled, which should be from the last reflog position to now.

    (I'm not confident that this always does the right thing, so often I just cut and paste the commit IDs that are printed by 'git pull'. It's a little bit more work but I trust my understanding more.)

  • slog = log --pretty=slog

    Normally if I'm reading a repo's log at all, I read the full log. But there are some repos where this isn't really useful and some situations where I just want a quick overview, so I only look at the short log. This goes along with the following in .gitconfig to actually define the 'slog' format:

        slog = format:* %s

  • pslog = log --pretty=slog @{1}..

    This is a combination of 'git plog' and 'git slog'; it shows me the log for the pull (theoretically) in short log form.

  • ffpull = pull --ff-only
    ffmerge = merge --ff-only

    These are two aliases I use if I don't entirely trust the upstream repo to not have rebased itself on me. The ffpull alias pulls with only a fast-forward operation allowed (the equivalent of setting 'git config pull.ff only', which I don't always remember to do), while ffmerge is what I use in worktrees.

(Probably I should set up a git alias or something that configures a newly cloned repo with all of the settings that I want. So far I think that's only 'pull.ff only', but there will probably be more in the future.)

I have other git aliases but in practice I mostly don't remember them (for instance, I have an 'idiff' alias for 'git diff --cached').

Comments on this page:

From at 2020-02-12 01:00:51:

One of my most used aliases is new = !tig @{1}.. because tig makes it far easier to browse history than the flat 'git log' does.

I don't remember where on StackOverflow (probably) I found this or what git version is required, but I have a pair of shell aliases:

alias ahead='git log --pretty=oneline --abbrev-commit $(git rev-parse --abbrev-ref --symbolic-full-name @{u})..'
alias behind='git log --pretty=oneline --abbrev-commit ..$(git rev-parse --abbrev-ref --symbolic-full-name @{u})'

This tells me what's in my local repo but not on upstream (ahead) and vice-versa (behind).

Before it fell unmaintained, I used git-sh a lot; now, I just have my most-used aliases from it in my .zshrc file. Plus some gentle enhancements like ahead/behind.

By Piero at 2020-02-12 16:20:08:

One of the most frequent actions on git repositories is looking at what I and others did. For this I use these aliases:

my = log --author=$LOGNAME
by = "!by() { cd ${GIT_PREFIX:-.}; whom=$1; shift; git log --author=$whom $@; }; by"

I have also found that looking at thing to be committed, was a frequent action, thus:

ss = "!ss() { git show 'stash@{'$1'}'; }; ss"

A few nontrivial ones from my config (

medit = "!git diff --name-only --diff-filter=U -z | xargs -0r grep -lZ '\<<<<<<<' | xargs -0ro vim '+/<<<<<<<'"

edits all files which contain merge markers.

madd = "!git diff --name-only --diff-filter=U -z | xargs -0r grep -LZ '<\<<<<<<' | xargs -0r git add -v"

adds all files which don't contain merge markers anymore.

sub = submodule update --init --recursive

does anything I ever need related to submodules in one call.

push-branch = push -u origin HEAD

pushes the current branch to origin, creating it if needed.

Written on 12 February 2020.
« Doing frequent ZFS scrubs lets you discover problems close to when they happened
You can't delegate a ZFS administration permission to delete only snapshots »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Feb 12 00:52:07 2020
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.