-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-config-recommended.sh
executable file
·133 lines (116 loc) · 7.87 KB
/
git-config-recommended.sh
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Git Recommended configuration
# These settings are meant to be nearly universal.
# They should be applicable on every computer and should be fine to include in your global ~/.gitconfig.
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -euxo pipefail
# Aliases
# Shorthand aliases
# Aliases from the git-scm book https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
# Aliases of my own that seem to be pretty common
git config --global alias.cp cherry-pick
git config --global alias.oops 'commit --amend --no-edit'
# there is no configuration available to tell git to always use `force-with-lease` instead of `force`
# https://stackoverflow.com/a/30567394/23572
git config --global alias.pushf 'push --force-with-lease'
# Aliases for plurals. Otherwise, git has inconsistent commands to list all branches, tags, stashes, workrees, remotes, aliases.
# Plurals from http://gggritso.com/human-git-aliases
git config --global alias.branches 'branch --all'
git config --global alias.tags 'tag --list'
git config --global alias.stashes 'stash list'
# https://stackoverflow.com/a/7067489/23572
git config --global alias.aliases 'config --get-regexp ^alias\.'
# More plurals
git config --global alias.worktrees 'worktree list'
git config --global alias.remotes 'remote --verbose'
# submodule configuration
# Diffs of submodules should show the changed contents rather than a list of commits.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-diffsubmodule
# Change from 'short' to 'diff'
git config --global diff.submodule diff
# git status should show a summary of commits for modified submodules.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-statussubmoduleSummary
git config --global status.submoduleSummary true
# git push should recurse into submodules on-demand
# all submodules that changed in the revisions to be pushed will be pushed
# Change from 'no' to 'on-demand'
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushrecurseSubmodules
git config --global push.recurseSubmodules on-demand
# diff
# Git should detect both renames and copies. Theoretically slows down git.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-diffrenames
# Change from 'true' to 'copies'
git config --global diff.renames copies
# git diff should use a prefix pair that is different from the standard "a/" and "b/" depending on what is being compared. Only relevant when not piping through a pager/formatter like diff-so-fancy.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-diffmnemonicPrefix
git config --global diff.mnemonicPrefix true
# rerere
# Reuse recorded resolution
# The git rerere functionality is a bit of a hidden feature. The name stands for "reuse recorded resolution" and, as the name implies, it allows you to ask Git to remember how you’ve resolved a hunk conflict so that the next time it sees the same conflict, Git can resolve it for you automatically.
# https://git-scm.com/book/en/v2/Git-Tools-Rerere
# Enable rerere
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-rerereenabled
# https://stackoverflow.com/questions/5519244/are-there-any-downsides-to-enabling-git-rerere
git config --global rerere.enabled true
# rerere should update the index, not just the worktree.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-rerereautoUpdate
git config --global rerere.autoUpdate true
# branch
# When a new branch is created with git branch or git checkout that tracks another branch, git should set up pull to rebase instead of merge.
# Change from 'never' to 'always'
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-branchautoSetupRebase
git config --global branch.autoSetupRebase always
# Tells git branch, git switch and git checkout to set up new branches so that git-pull will merge from the starting point branch.
# true: automatic setup is done when the starting point is a remote-tracking branch;
# always: automatic setup is done when the starting point is either a local branch or remote-tracking branch;
# Change from 'true' to 'always'
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-branchautoSetupMerge
git config --global branch.autoSetupMerge always
# AutoStash
# Automatically stash local changes before rebase and merge operations.
# Create a temporary stash entry before and apply it after.
# This means that you can run rebase on a dirty worktree.
# Use with care: the final stash application after a successful rebase might result in non-trivial conflicts.
# This option can be overridden by the --no-autostash and --autostash options of git-rebase.
# Auto-stash before rebase
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-rebaseautoStash
git config --global rebase.autoStash true
# Auto-stash before merge
# https://stackoverflow.com/a/30209750/23572
# Coming in Git 2.27. Current version at time of writing is 2.26.2.
git config --global merge.autoStash true
# rebase
# https://github.blog/2022-10-03-highlights-from-git-2-38/#rebase-dependent-branches-with-update-refs
git config --global rebase.updateRefs true
# git log should act as if the --follow option was used when a single <path> is given
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-logfollow
# https://git-scm.com/docs/git-log#Documentation/git-log.txt---follow
# Continue listing the history of a file beyond renames (works only for a single file).
git config --global log.follow true
# git stash show (without an option) should show the stash entry in patch form.
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-stashshowPatch
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-stashshowStat
git config --global stash.showPatch true
# Performance
# Use merge-ort merge strategy
# https://github.blog/2021-08-16-highlights-from-git-2-33/#merge-ort-a-new-merge-strategy
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-pulltwohead
git config --global pull.twohead ort
# Use file system monitor
# https://github.blog/2022-06-29-improve-git-monorepo-performance-with-a-file-system-monitor/
# added in Git version 2.37.0
git config --global core.fsmonitor true
git config --global core.untrackedcache true
# Default branch name
# https://github.blog/2020-07-27-highlights-from-git-2-28/#introducing-init-defaultbranch
git config --global init.defaultBranch main
# Remote
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-remotepushDefault
# The remote to push to by default. Overrides branch.<name>.remote for all branches, and is overridden by branch.<name>.pushRemote for specific branches.
git config --global remote.pushDefault origin