-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitConfig.html
300 lines (251 loc) · 22.5 KB
/
GitConfig.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mantid Git Config</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/bootstrap-sphinx.css?v=fadd4351" />
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=77160d70" />
<script src="_static/documentation_options.js?v=a8da1a53"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Mantid Git Workflow" href="GitWorkflow.html" />
<link rel="prev" title="User Support" href="UserSupport.html" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59110517-1', 'auto');
ga('send', 'pageview');
</script>
</head><body>
<div id="navbar" class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.mantidproject.org">
</a>
<span class="navbar-text navbar-version pull-left"><b>main</b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li class="divider-vertical"></li>
<li><a href="index.html">Home</a></li>
<li><a href="https://download.mantidproject.org">Download</a></li>
<li><a href="https://docs.mantidproject.org">User Documentation</a></li>
<li><a href="http://www.mantidproject.org/contact">Contact Us</a></li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<p>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="nav-item nav-item-0"><a href="index.html">Documentation</a> »</li>
<li class="nav-item nav-item-this"><a href="">Mantid Git Config</a></li>
</ul>
</div> </p>
</div>
<div class="container">
<div class="row">
<div class="body col-md-12 content" role="main">
<section id="mantid-git-config">
<span id="gitconfig"></span><h1>Mantid Git Config<a class="headerlink" href="#mantid-git-config" title="Link to this heading">¶</a></h1>
<nav class="contents local" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#summary" id="id1">Summary</a></p></li>
<li><p><a class="reference internal" href="#recommended-config" id="id2">Recommended Config</a></p></li>
<li><p><a class="reference internal" href="#diff-merge-tools" id="id3">Diff/Merge Tools</a></p></li>
<li><p><a class="reference internal" href="#useful-aliases" id="id4">Useful Aliases</a></p></li>
<li><p><a class="reference internal" href="#more-advanced-options" id="id5">More Advanced Options</a></p></li>
</ul>
</nav>
<section id="summary">
<h2><a class="toc-backref" href="#id1" role="doc-backlink">Summary</a><a class="headerlink" href="#summary" title="Link to this heading">¶</a></h2>
<p>This page describes some configuration that will help with your usage of Git - some of which is strongly recommended. This should all be added to the <code class="docutils literal notranslate"><span class="pre">.gitconfig</span></code> file in your user home directory, i.e. <code class="docutils literal notranslate"><span class="pre">~/</span></code> on Linux or <code class="docutils literal notranslate"><span class="pre">%USERPROFILE%</span></code> on Windows. This will then be global across all of your repositories - please sanity check these suggestions if you use git for other repositories.</p>
<p>Note that some of the values are commented out because they must be updated with your own details or are OS specific. Some commands use third party tools which may need to be installed.</p>
</section>
<section id="recommended-config">
<h2><a class="toc-backref" href="#id2" role="doc-backlink">Recommended Config</a><a class="headerlink" href="#recommended-config" title="Link to this heading">¶</a></h2>
<p>It is recommended to set up the following as a minimum:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>user<span class="o">]</span>
<span class="w"> </span><span class="c1"># Uncomment and set these to your own details</span>
<span class="w"> </span><span class="c1">#name =</span>
<span class="w"> </span><span class="c1">#email =</span>
<span class="o">[</span>core<span class="o">]</span>
<span class="w"> </span><span class="c1"># Uncomment and set an editor you like. If you're not sure, try Nano on Linux or Notepad++ on Windows</span>
<span class="w"> </span><span class="c1">#editor = nano</span>
<span class="w"> </span><span class="c1">#editor = "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"</span>
<span class="w"> </span><span class="c1"># Specify your own global list of files/patterns that git should ignore</span>
<span class="w"> </span><span class="nv">excludesfile</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>~/.gitignore
<span class="w"> </span><span class="c1"># Fix up line endings between windows/linux - uncomment one</span>
<span class="w"> </span><span class="c1"># Linux</span>
<span class="w"> </span><span class="c1">#autocrlf = input</span>
<span class="w"> </span><span class="c1"># Windows</span>
<span class="w"> </span><span class="c1">#autocrlf = true</span>
<span class="o">[</span>log<span class="o">]</span>
<span class="w"> </span><span class="c1"># Get the log to follow files even if they were renamed</span>
<span class="w"> </span><span class="nv">follow</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="o">[</span>fetch<span class="o">]</span>
<span class="w"> </span><span class="c1"># Remove remote-tracking references that no longer exist on the remote when you do a fetch/pull</span>
<span class="w"> </span><span class="nv">prune</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="o">[</span>push<span class="o">]</span>
<span class="w"> </span><span class="c1"># The safest default for git-push: push only the current branch and only if it has the same name as upstream</span>
<span class="w"> </span><span class="nv">default</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>simple
<span class="o">[</span>pull<span class="o">]</span>
<span class="w"> </span><span class="c1"># Only pull the current branch by default</span>
<span class="w"> </span><span class="nv">default</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>current
<span class="w"> </span><span class="c1"># Only allow pull if it can be fast-forwarded (otherwise you explicitly need to merge in the remote or rebase onto it e.g. with git pull --rebase)</span>
<span class="w"> </span><span class="nv">ff</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>only
<span class="o">[</span>diff<span class="o">]</span>
<span class="w"> </span><span class="c1"># Add extra colours for highlighting moved code</span>
<span class="w"> </span><span class="nv">colorMoved</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>default
<span class="o">[</span>merge<span class="o">]</span>
<span class="w"> </span><span class="c1"># Include the common ancestor in conflict details - very useful for working out which changes to keep</span>
<span class="w"> </span><span class="nv">conflictstyle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>diff3
<span class="o">[</span>rebase<span class="o">]</span>
<span class="w"> </span><span class="c1"># Automatically reposition !fixup/!squash commits in interactive rebase (useful with git commit --fixup/squash)</span>
<span class="w"> </span><span class="nv">autosquash</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
</pre></div>
</div>
</section>
<section id="diff-merge-tools">
<h2><a class="toc-backref" href="#id3" role="doc-backlink">Diff/Merge Tools</a><a class="headerlink" href="#diff-merge-tools" title="Link to this heading">¶</a></h2>
<p>You may find the following diff/merge tools helpful:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="c1"># Uncomment lines where appropriate for specific OS</span>
<span class="o">[</span>diff<span class="o">]</span>
<span class="w"> </span><span class="c1"># Set up a graphical tool for viewing diffs. I like meld because it looks good and</span>
<span class="w"> </span><span class="c1"># does a good job with directory diffs</span>
<span class="w"> </span><span class="nv">tool</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>meld
<span class="o">[</span>difftool<span class="o">]</span>
<span class="w"> </span><span class="c1"># Disable the prompt when opening the difftool</span>
<span class="w"> </span><span class="nv">prompt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">false</span>
<span class="o">[</span>merge<span class="o">]</span>
<span class="w"> </span><span class="c1"># Specify a graphical tool for resolving merge conflicts. I like diffmerge because you</span>
<span class="w"> </span><span class="c1"># can toggle between the merged file and common ancestor</span>
<span class="w"> </span><span class="nv">tool</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>diffmerge
<span class="o">[</span>difftool<span class="w"> </span><span class="s2">"meld"</span><span class="o">]</span>
<span class="w"> </span><span class="nv">external</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>meld
<span class="w"> </span><span class="c1"># Windows</span>
<span class="w"> </span><span class="c1">#cmd = "'C:/Program Files (x86)/Meld/Meld.exe' $LOCAL $REMOTE"</span>
<span class="w"> </span><span class="c1">#path = C:/Program Files (x86)/Meld/Meld.exe</span>
<span class="o">[</span>mergetool<span class="w"> </span><span class="s2">"meld"</span><span class="o">]</span>
<span class="w"> </span><span class="nv">trustExitCode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="w"> </span><span class="nv">keepBackup</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">false</span>
<span class="w"> </span><span class="c1"># Windows</span>
<span class="w"> </span><span class="c1">#cmd = "'C:/Program Files (x86)/Meld/Meld.exe' $LOCAL $BASE $REMOTE --output=$MERGED"</span>
<span class="w"> </span><span class="c1">#path = C:/Program Files (x86)/Meld/Meld.exe</span>
<span class="o">[</span>difftool<span class="w"> </span><span class="s2">"diffmerge"</span><span class="o">]</span>
<span class="w"> </span><span class="c1"># Linux</span>
<span class="w"> </span><span class="c1">#cmd = diffmerge $LOCAL $REMOTE</span>
<span class="w"> </span><span class="c1"># Windows</span>
<span class="w"> </span><span class="c1">#cmd = "'C:/Program Files/SourceGear/common/DiffMerge/sgdm.exe' $LOCAL $REMOTE"</span>
<span class="o">[</span>mergetool<span class="w"> </span><span class="s2">"diffmerge"</span><span class="o">]</span>
<span class="w"> </span><span class="nv">trustExitCode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="w"> </span><span class="nv">keepBackup</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">false</span>
<span class="w"> </span><span class="c1"># Linux</span>
<span class="w"> </span><span class="c1">#cmd = diffmerge -merge -result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"</span>
<span class="w"> </span><span class="c1"># Windows</span>
<span class="w"> </span><span class="c1">#cmd = "'C:/Program Files/SourceGear/common/DiffMerge/sgdm.exe' -merge -result=$MERGED $LOCAL $BASE $REMOTE"</span>
</pre></div>
</div>
</section>
<section id="useful-aliases">
<h2><a class="toc-backref" href="#id4" role="doc-backlink">Useful Aliases</a><a class="headerlink" href="#useful-aliases" title="Link to this heading">¶</a></h2>
<p>You may find the following aliases helpful. You can also add your own.</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>pretty<span class="o">]</span>
<span class="w"> </span><span class="nv">concise</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"%C(yellow)%h%Creset %C(green)[%ar]%Creset %C(auto)%d%Creset %s %C(cyan)<%an>"</span>
<span class="w"> </span><span class="nv">detail</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"%C(yellow)commit %h%Creset%C(auto)%d%Creset%n%C(yellow)Parents: %p%Creset%n%C(cyan)Author: %an <%ae>%Creset%n%C(cyan) %ai (%ar)%Creset%n%C(green)Commit: %cn <%ce>%Creset%n%C(green) %ci (%cr)%Creset%n%n%w(79)%s%n%n%b"</span>
<span class="o">[</span>alias<span class="o">]</span>
<span class="w"> </span><span class="c1"># Check out a pull request for testing. The first argument is the name of the remote and the</span>
<span class="w"> </span><span class="c1"># second is the pull request number,</span>
<span class="w"> </span><span class="c1"># e.g. git test-pr origin 12345</span>
<span class="w"> </span>test-pr<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"!f() { git fetch </span><span class="nv">$1</span><span class="s2"> pull/</span><span class="nv">$2</span><span class="s2">/merge:pr/</span><span class="nv">$2</span><span class="s2">-merged && git checkout pr/</span><span class="nv">$2</span><span class="s2">-merged; }; f"</span>
<span class="w"> </span><span class="c1"># Remove all branches starting pr/</span>
<span class="w"> </span>test-pr-remove-all<span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"!f() { git branch | grep pr/ | xargs git branch -D; }; f"</span>
<span class="w"> </span><span class="c1"># Get into the habit of using add --patch to create focused commits</span>
<span class="w"> </span><span class="nv">ap</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>add<span class="w"> </span>--patch
<span class="w"> </span><span class="c1"># Amend the latest commit</span>
<span class="w"> </span><span class="nv">ca</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>commit<span class="w"> </span>--amend
<span class="w"> </span><span class="c1"># Amend the latest commit reuse commit message from latest commit</span>
<span class="w"> </span><span class="nv">cah</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>commit<span class="w"> </span>--amend<span class="w"> </span>--reuse-message<span class="o">=</span>HEAD
<span class="w"> </span><span class="c1"># Pretty oneline log with a bit more info than git log --oneline</span>
<span class="w"> </span><span class="nv">lg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>log<span class="w"> </span>--pretty<span class="o">=</span>concise
<span class="w"> </span><span class="c1"># Pretty log showing as a graph</span>
<span class="w"> </span><span class="nv">lgg</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>log<span class="w"> </span>--pretty<span class="o">=</span>concise<span class="w"> </span>--graph
<span class="w"> </span><span class="c1"># Pretty log showing only the commits on the current branch i.e. since main</span>
<span class="w"> </span><span class="nv">lgm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>log<span class="w"> </span>--pretty<span class="o">=</span>concise<span class="w"> </span>main..
<span class="w"> </span><span class="c1"># Show all of the files changed on the current branch i.e. since main</span>
<span class="w"> </span><span class="nv">lfc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"!f() { git log --name-only --format= main.. | sort | uniq; }; f"</span>
<span class="w"> </span><span class="c1"># Show commit details with file names only</span>
<span class="w"> </span><span class="nv">sh</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>show<span class="w"> </span>--stat<span class="w"> </span>--pretty<span class="o">=</span>detail
<span class="w"> </span><span class="c1"># Show commit details including diffs (same as git-show but slightly prettier)</span>
<span class="w"> </span><span class="nv">shd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>show<span class="w"> </span>--pretty<span class="o">=</span>detail
<span class="w"> </span><span class="c1"># A more concise output from status, also showing which branch you're on</span>
<span class="w"> </span><span class="nv">st</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>status<span class="w"> </span>--short<span class="w"> </span>--branch
<span class="w"> </span><span class="c1"># A more verbose output from branch, showing the commit and upstream branch</span>
<span class="w"> </span><span class="nv">br</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>branch<span class="w"> </span>-vv
<span class="w"> </span><span class="c1"># When pushing a new branch upstream, set the local branch to track it</span>
<span class="w"> </span><span class="nv">pushu</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>push<span class="w"> </span>--set-upstream
<span class="w"> </span><span class="c1"># Force push with lease (safer than push --force, but still be careful when changing history)</span>
<span class="w"> </span><span class="nv">pushfl</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>push<span class="w"> </span>--force-with-lease
</pre></div>
</div>
</section>
<section id="more-advanced-options">
<h2><a class="toc-backref" href="#id5" role="doc-backlink">More Advanced Options</a><a class="headerlink" href="#more-advanced-options" title="Link to this heading">¶</a></h2>
<p>The following may be useful if you get into more in-depth usage of Git:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="o">[</span>rerere<span class="o">]</span>
<span class="w"> </span><span class="c1"># Reuse Recorded Resolutions - useful if you find yourself fixing the same conflicts over and over</span>
<span class="w"> </span><span class="nv">enabled</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="w"> </span><span class="c1"># Auto-stage files resolved by rerere</span>
<span class="w"> </span><span class="nv">autoupdate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">true</span>
<span class="o">[</span>blame<span class="o">]</span>
<span class="w"> </span><span class="c1"># This file allows you to specify commits that should be ignored in git-blame e.g. bulk changes</span>
<span class="w"> </span><span class="nv">ignoreRevsFile</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>~/.git-blame-ignore-revs
<span class="o">[</span>include<span class="o">]</span>
<span class="w"> </span><span class="c1"># You can split your config into sub-files e.g. to include common config on different OS's</span>
<span class="w"> </span><span class="nv">path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>~/.gitconfig_common
</pre></div>
</div>
</section>
</section>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<ul class="nav navbar-nav" style=" float: right;">
<li>
<a href="UserSupport.html" title="Previous Chapter: User Support"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm hidden-tablet">« User Support</span>
</a>
</li>
<li>
<a href="GitWorkflow.html" title="Next Chapter: Mantid Git Workflow"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm hidden-tablet">Mantid Git Workflow »</span>
</a>
</li>
<li><a href="#">Back to top</a></li>
</ul>
<p>
</p>
</div>
</footer>
</body>
</html>