summaryrefslogtreecommitdiff
path: root/aliases.gitconfig
blob: 50cc24f5c5d605990834fa021deb456fc9631d5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
[alias]
	## Alias management
	# List aliases: `git aliases`
	aliases	= config --global --get-regexp alias[.]

	## Remote management
	# Bring all remotes up to date: `git fall` (this is morally
	# equivalent to `git remote update --prune`, but easier to type).
	fall	= fetch --all --prune
	# Bring this branch up to date with its upstream, safely: `git up`
	# This will fail (intentionally) if the current branch has diverged
	# from upstream; use `git reset`, `git rebase`, or `git merge` to
	# re-converge the branch as appropriate. I generally only use this to
	# bring local `master` up to date with `origin/master` immediately
	# before using `git accept`.
	up	= pull --ff --ff-only
	# Fast-forward the current branch: `git ff [BRANCHNAME]`. Morally
	# equivalent to `git up` if you fetch things by hand and have
	# `merge.defaultToUpstream` set to `true` (which you should).)
	ff	= merge --ff --ff-only
	# Configure `origin` to fetch Github pull requests: `git prhub` - this
	# will cause `git fetch` to create local refs named `refs/pull/N` for
	# each pull request's source branch.
	prhub	= config --add remote.origin.fetch +refs/pull/*/head:refs/pull/*
	# Configure `origin` to fetch Stash pull requests: `git prstash`
	# Atlassian is very insistent that these refs are for internal use
	# only and are unsupported; they've changed how they work at least
	# once in recent history. If this breaks, you get to keep both pieces.
	prstash	= config --add remote.origin.fetch +refs/pull-requests/*/from:refs/pull/*

	## Branch lifecycle
	# Create a branch: `git start BRANCHNAME` (protip: run `git fall`
	# first.) The new branch will track origin/master by default.
	# Tracking info gets used below.
	start	= checkout --track origin/master -b
	# Branch log for the current branch: `git blog [log options]`
	blog	= log HEAD@{upstream}..HEAD
	# Branch one-line summary (equivalent to `git blog --oneline`)
	bsummary	= log --oneline HEAD@{upstream}..HEAD
	# Aggregate diff of the current branch: `git bdiff [diff options]`
	bdiff	= diff HEAD@{upstream}...HEAD
	# Upload a branch to personal fork: `git publish` - note that this
	# will unconditionally overwrite the branch if it already exists,
	# potentially "losing" changes. Don't `git publish` master. Because of
	# limitations in git's aliases mechanism, this DOES NOT support `git
	# publish BRANCHNAME` the way you'd expect.
	publish	= !git push "${USER}" +HEAD
	# "Accept" a branch by merging it: `git accept BRANCHNAME` - this
	# always creates a merge commit if it succeeds, making it easier to
	# pick out branch merges in history. (See `git up`, above, for more
	# usage advice.)
	accept	= merge --no-ff
	# Rewrite the current branch, in place: `git rewrite` - unlike `git
	# rebase`, this does _not_ advance the branch onto new upstream
	# changes. You can use this to clean up branch history without
	# worrying about conflicts with others' changes at the same time.
	rewrite	= rebase --interactive --onto HEAD...@{upstream}
	# Create a branch detached from history: `git sever BRANCHNAME` - this
	# is a bit of a niche command; I create expurgated branches from
	# private projects more often than some people.
	sever	= checkout --detach
  # Delete all branches merged into origin/maser: `git prune-merged`
	prune-merged = "!f() { git for-each-ref refs/heads/* --merged | while read hash type ref; do branch=\"$(git rev-parse --abbrev-ref \"${ref}\")\"; git branch -d \"${branch}\"; done; }; f"

	## Commit authoring
	## The following aliases interact with `git rebase --autosquash`; I
	## recommend setting `rebase.autosquash` to `true` to make this the
	## default behaviour. See `man git-rebase` for a thorough explanation.
	# Stage the work tree, verbatim, including removals and renames: `git
	# this` - try to keep `git status` clean all the time, or this will
	# make you so, so sad. `.git/info/exclude` is a great help for this.
	this	= add --all :/
	# Stage this subdirectory of the work tree, verbatim, including
	# removals and renames: `git these`.
	these	= add --all .
	# Replace the most recent commit: `git amend [commit options]`.
	amend	= commit --amend --no-edit
	# Retrofit changes onto an old commit during the next rebase/rewrite:
	# `git fixup COMMITISH` (for example, `git fixup HEAD`).
	fixup	= commit --fixup
  # Retrofit changes onto an old commit during the next rebase/rewrite,
  # adding an additional comment `git squash COMMITISH` (for example,
  # `git squash HEAD`).
  squash = commit --squash
  # Create a meaningless commit with a unique message: `git wip`.
	wip = "!f() { git this && git commit -m \"wip: $(uuidgen)\"; }; f"

	## Working with history
	# Simple text-based commit graph: `git lol [BRANCHES|--all]`
	lol	= log --graph --oneline --decorate