@@ -29,8 +29,14 @@ Making a new feature branch
29
29
30
30
::
31
31
32
- git branch my-new-feature
33
- git checkout my-new-feature
32
+ git checkout -b my-new-feature master
33
+
34
+ This will create and immediately check out a feature branch based on
35
+ ``master ``. To create a feature branch based on a maintenance branch,
36
+ use::
37
+
38
+ git fetch origin
39
+ git checkout -b my-new-feature origin/v1.0.x
34
40
35
41
Generally, you will want to keep this also on your public github _ fork
36
42
of matplotlib _. To do this, you `git push `_ this new branch up to your github _
@@ -40,13 +46,16 @@ by default), git will have a link to your github_ repo, called
40
46
41
47
git push origin my-new-feature
42
48
43
- In git >1.7 you can ensure that the link is correctly set by using the
44
- ``--set-upstream `` option::
49
+ You will need to use this exact command, rather than simply ``git
50
+ push `` every time you want to push changes on your feature branch to
51
+ your github _ repo. However, in git >1.7 you can set up a link by
52
+ using the ``--set-upstream `` option::
45
53
46
54
git push --set-upstream origin my-new-feature
47
55
48
- From now on git _ will know that ``my-new-feature `` is related to the
49
- ``my-new-feature `` branch in the github _ repo.
56
+ and then next time you need to push changes to your branch a simple
57
+ ``git push `` will suffice. Note that ``git push `` pushes out all
58
+ branches that are linked to a remote branch.
50
59
51
60
The editing workflow
52
61
====================
@@ -73,12 +82,12 @@ In more detail
73
82
# (use "git add <file>..." to update what will be committed)
74
83
# (use "git checkout -- <file>..." to discard changes in working directory)
75
84
#
76
- # modified: README
85
+ # modified: README
77
86
#
78
87
# Untracked files:
79
88
# (use "git add <file>..." to include in what will be committed)
80
89
#
81
- # INSTALL
90
+ # INSTALL
82
91
no changes added to commit (use "git add" and/or "git commit -a")
83
92
84
93
#. Check what the actual changes are with ``git diff `` (`git diff `_).
@@ -125,7 +134,7 @@ without interfering with the output from the comparison. More detail?
125
134
Note the three dots in the URL above (``master...my-new-feature ``) and
126
135
see :ref: `dot2-dot3 `.
127
136
128
- Asking for your changes to be merged with the main repo
137
+ Asking for your changes to be merged into the main repo
129
138
=======================================================
130
139
131
140
When you are ready to ask for the merge of your code:
@@ -140,10 +149,16 @@ When you are ready to ask for the merge of your code:
140
149
recipient. The message will go to the `matplotlib mailing list `_. Please
141
150
feel free to add others from the list as you like.
142
151
143
- Merging from trunk
144
- ==================
152
+ #. If the branch is to be merged into a maintenance branch on the main
153
+ repo, make sure the "base branch" indicates the maintenance branch
154
+ and not master. Github can not automatically determine the branch
155
+ to merge into.
145
156
146
- This updates your code from the upstream `matplotlib github `_ repo.
157
+ Staying up to date with changes in the central repository
158
+ =========================================================
159
+
160
+ This updates your working copy from the upstream `matplotlib github `_
161
+ repo.
147
162
148
163
Overview
149
164
--------
@@ -155,7 +170,7 @@ Overview
155
170
# pull changes from github
156
171
git fetch upstream
157
172
# merge from upstream
158
- git merge upstream/master
173
+ git merge --ff-only upstream/master
159
174
160
175
In detail
161
176
---------
@@ -175,7 +190,72 @@ the upstream repo to a copy on your local machine::
175
190
176
191
then merging into your current branch::
177
192
178
- git merge upstream/master
193
+ git merge --ff-only upstream/master
194
+
195
+ The ``--ff-only `` option guarantees that if you have mistakenly
196
+ committed code on your ``master `` branch, the merge fails at this point.
197
+ If you were to merge ``upstream/master `` to your ``master ``, you
198
+ would start to diverge from the upstream. If this command fails, see
199
+ the section on accidents _.
200
+
201
+ The letters 'ff' in ``--ff-only `` mean 'fast forward', which is a
202
+ special case of merge where git can simply update your branch to point
203
+ to the other branch and not do any actual merging of files. For
204
+ ``master `` and other integration branches this is exactly what you
205
+ want.
206
+
207
+ Other integration branches
208
+ --------------------------
209
+
210
+ Some people like to keep separate local branches corresponding to the
211
+ maintenance branches on github. At the time of this writing, ``v1.0.x ``
212
+ is the active maintenance branch. If you have such a local branch,
213
+ treat is just as ``master ``: don't commit on it, and before starting
214
+ new branches off of it, update it from upstream::
215
+
216
+ git checkout v1.0.x
217
+ git fetch upstream
218
+ git merge --ff-only upstream/v1.0.x
219
+
220
+ But you don't necessarily have to have such a branch. Instead, if you
221
+ are preparing a bugfix that applies to the maintenance branch, fetch
222
+ from upstream and base your bugfix on the remote branch::
223
+
224
+ git fetch upstream
225
+ git checkout -b my-bug-fix upstream/v1.0.x
226
+
227
+ .. _accidents :
228
+
229
+ Recovering from accidental commits on master
230
+ --------------------------------------------
231
+
232
+ If you have accidentally committed changes on ``master `` and
233
+ ``git merge --ff-only `` fails, don't panic! First find out how much
234
+ you have diverged::
235
+
236
+ git diff upstream/master...master
237
+
238
+ If you find that you want simply to get rid of the changes, reset
239
+ your ``master `` branch to the upstream version::
240
+
241
+ git reset --hard upstream/master
242
+
243
+ As you might surmise from the words 'reset' and 'hard', this command
244
+ actually causes your changes to the current branch to be lost, so
245
+ think twice.
246
+
247
+ If, on the other hand, you find that you want to preserve the changes,
248
+ create a feature branch for them::
249
+
250
+ git checkout -b my-important-changes
251
+
252
+ Now ``my-important-changes `` points to the branch that has your
253
+ changes, and you can safely reset ``master `` as above |emdash | but
254
+ make sure to reset the correct branch::
255
+
256
+ git checkout master
257
+ git reset --hard upstream/master
258
+
179
259
180
260
Deleting a branch on github _
181
261
============================
0 commit comments