Skip to content

Commit 4d08427

Browse files
authored
Merge pull request #216 from dpshelio/git-updates
Sets merge commit as default when pulling, and other branching changes
2 parents 963207c + c3b79b8 commit 4d08427

9 files changed

+64
-39
lines changed

ch02git/01Intro.ipynb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,30 @@
387387
"git config --global user.email \"[email protected]\""
388388
]
389389
},
390+
{
391+
"cell_type": "markdown",
392+
"metadata": {},
393+
"source": [
394+
"Additionally, it's also a good idea to define what's the name of the default branch when we create a repository:"
395+
]
396+
},
397+
{
398+
"cell_type": "code",
399+
"execution_count": null,
400+
"metadata": {},
401+
"outputs": [],
402+
"source": [
403+
"%%bash\n",
404+
"git config --global init.defaultBranch main"
405+
]
406+
},
407+
{
408+
"cell_type": "markdown",
409+
"metadata": {},
410+
"source": [
411+
"Historically, the default branch was named `master`. Nowadays, the community and most of the hosting sites have changed the default ([read about this change in GitHub](https://github.com/github/renaming/) and [Gitlab](https://about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/)."
412+
]
413+
},
390414
{
391415
"cell_type": "markdown",
392416
"metadata": {},

ch02git/04Publishing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
],
145145
"source": [
146146
"%%bash\n",
147-
"git push -uf origin master # I have an extra `f` switch here.\n",
147+
"git push -uf origin main # I have an extra `f` switch here.\n",
148148
" #You should copy the instructions from YOUR repository."
149149
]
150150
},

ch02git/05Collaboration.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@
512512
"cell_type": "markdown",
513513
"metadata": {},
514514
"source": [
515-
"Do as it suggests:"
515+
"Do as it suggests. However, we need first to tell git how we want it to act when there are diverging branches (as in this case). We will set the default to be to create a merge commit, then we proceed to `pull`."
516516
]
517517
},
518518
{
@@ -547,6 +547,7 @@
547547
],
548548
"source": [
549549
"%%bash\n",
550+
"git config --global pull.rebase false\n",
550551
"git pull"
551552
]
552553
},

ch02git/06ForkAndPull.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"It's a good practice to create a new branch that'll contain the changes we want. We'll learn more about branches later on. For now, just think of this as a separate area where our changes will be kept not to interfere with other people's work.\n",
9696
"\n",
9797
"```\n",
98-
"git checkout -b southwest\n",
98+
"git switch -c southwest\n",
9999
"```"
100100
]
101101
},
@@ -209,7 +209,7 @@
209209
"\n",
210210
"* Numpy's example is only illustrative. Normally, Open Source projects have in their documentation (sometimes in the form of a wiki) a set of instructions you need to follow if you want to contribute to their software.\n",
211211
"\n",
212-
"* Pull Requests can also be done for merging branches in a non-forked repository. It's typically used in teams to merge code from a branch into the master branch and ask team colleagues for code reviews before merging.\n",
212+
"* Pull Requests can also be done for merging branches in a non-forked repository. It's typically used in teams to merge code from a branch into the `main` branch and ask team colleagues for code reviews before merging.\n",
213213
"\n",
214214
"* It's a good practice before starting a fork and a pull request to have a look at existing forks and pull requests. On GitHub, you can find the list of pull requests on the horizontal menu on the top of the page. Try to also find the network graph displaying all existing forks of a repo, e.g., [NumpyDoc repo's network graph](https://github.com/numpy/numpydoc/network)."
215215
]

ch02git/10Branches.ipynb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
],
8080
"source": [
8181
"%%bash\n",
82-
"git checkout -b experiment # Make a new branch"
82+
"git switch -c experiment # Make a new branch (use instead `checkout -b` if you have a version of git older than 2.23)"
8383
]
8484
},
8585
{
@@ -180,7 +180,7 @@
180180
],
181181
"source": [
182182
"%%bash\n",
183-
"git checkout master # Switch to an existing branch"
183+
"git switch main # Switch to an existing branch (use `checkout` if you are using git older than 2.23)"
184184
]
185185
},
186186
{
@@ -233,7 +233,7 @@
233233
],
234234
"source": [
235235
"%%bash\n",
236-
"git checkout experiment"
236+
"git switch experiment"
237237
]
238238
},
239239
{
@@ -325,7 +325,7 @@
325325
"cell_type": "markdown",
326326
"metadata": {},
327327
"source": [
328-
"If others checkout your repository, they will be able to do `git checkout experiment` to see your branch content,\n",
328+
"If others checkout your repository, they will be able to do `git switch experiment` to see your branch content,\n",
329329
"and collaborate with you **in the branch**."
330330
]
331331
},
@@ -410,7 +410,7 @@
410410
"outputs": [],
411411
"source": [
412412
"%%bash\n",
413-
"git log master..experiment"
413+
"git log main..experiment"
414414
]
415415
},
416416
{
@@ -525,7 +525,7 @@
525525
],
526526
"source": [
527527
"%%bash\n",
528-
"git checkout master"
528+
"git switch main"
529529
]
530530
},
531531
{
@@ -612,7 +612,7 @@
612612
],
613613
"source": [
614614
"%%bash\n",
615-
"git commit -am \"Commit Aonach onto master branch\""
615+
"git commit -am \"Commit Aonach onto main branch\""
616616
]
617617
},
618618
{
@@ -642,7 +642,7 @@
642642
],
643643
"source": [
644644
"%%bash\n",
645-
"git log --left-right --oneline master...experiment"
645+
"git log --left-right --oneline main...experiment"
646646
]
647647
},
648648
{
@@ -877,11 +877,11 @@
877877
"source": [
878878
"### A good branch strategy\n",
879879
"\n",
880-
"* A `production` branch: code used for active work\n",
881-
"* A `develop` branch: for general new code\n",
882-
"* `feature` branches: for specific new ideas\n",
883-
"* `release` branches: when you share code with others\n",
884-
" * Useful for isolated bug fixes"
880+
"* A `develop` or `main` branch: for general new code - (the cutting edge version of your software)\n",
881+
"* `feature` branches: for specific new ideas. Normally branched out from `main`.\n",
882+
"* `release` branches: when you share code with users. A particular moment of the `develop` process that it's considered stable.\n",
883+
" * Useful for including security and bug patches once it's been released.\n",
884+
"* A `production` branch: code used for active work. Normally it's the same than the latest release."
885885
]
886886
},
887887
{
@@ -914,10 +914,10 @@
914914
"metadata": {},
915915
"source": [
916916
"to quickly grab a file from one branch into another. This will create a copy of the file as it exists in `<branch>` into your current branch, overwriting it if it already existed.\n",
917-
"For example, if you have been experimenting in a new branch but want to undo all your changes to a particular file (that is, restore the file to its version in the `master` branch), you can do that with:\n",
917+
"For example, if you have been experimenting in a new branch but want to undo all your changes to a particular file (that is, restore the file to its version in the `main` branch), you can do that with:\n",
918918
"\n",
919919
"```\n",
920-
"git checkout master test_file\n",
920+
"git checkout main test_file\n",
921921
"```\n",
922922
"\n",
923923
"Using `git checkout` with a path takes the content of files.\n",

ch02git/11Miscellany.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@
796796
"source": [
797797
"%%bash\n",
798798
"\n",
799-
"git checkout -b gh-pages\n",
799+
"git switch -c gh-pages\n",
800800
"git push -uf origin gh-pages"
801801
]
802802
},

ch02git/12Remotes.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
],
9898
"source": [
9999
"%%bash\n",
100-
"git checkout master\n",
100+
"git switch main\n",
101101
"git remote add rits [email protected]:ucl-rits/github-example.git\n",
102102
"git remote -v"
103103
]
@@ -189,7 +189,7 @@
189189
],
190190
"source": [
191191
"%%bash\n",
192-
"git push -uf rits master"
192+
"git push -uf rits main"
193193
]
194194
},
195195
{
@@ -231,7 +231,7 @@
231231
"source": [
232232
"%%bash\n",
233233
"git fetch\n",
234-
"git log --oneline --left-right rits/master...origin/master"
234+
"git log --oneline --left-right rits/main...origin/main"
235235
]
236236
},
237237
{
@@ -264,7 +264,7 @@
264264
],
265265
"source": [
266266
"%%bash\n",
267-
"git diff --name-only origin/master"
267+
"git diff --name-only origin/main"
268268
]
269269
},
270270
{
@@ -415,7 +415,7 @@
415415
"source": [
416416
"%%bash\n",
417417
"git remote add local_bare ../bare_repo\n",
418-
"git push -u local_bare master"
418+
"git push -u local_bare main"
419419
]
420420
},
421421
{
@@ -474,7 +474,7 @@
474474
"git init --bare\n",
475475
"exit\n",
476476
"git remote add <somename> ssh://user@host/mygitserver\n",
477-
"git push -u <somename> master\n",
477+
"git push -u <somename> main\n",
478478
"```"
479479
]
480480
},

ch02git/13Rebase.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"\n",
2121
"### An example rebase\n",
2222
"\n",
23-
"We've built a repository to help visualise the difference between a merge and a rebase, at https://github.com/UCL-RITS/wocky_rebase/blob/master/wocky.md ."
23+
"We've built a [repository to help visualise the difference between a merge and a rebase](https://github.com/UCL-RITS/wocky_rebase/blob/main/wocky.md)."
2424
]
2525
},
2626
{
@@ -39,7 +39,7 @@
3939
"cell_type": "markdown",
4040
"metadata": {},
4141
"source": [
42-
"On the master branch, a second commit ('Dancing') has been added:"
42+
"On the `main` branch, a second commit ('Dancing') has been added:"
4343
]
4444
},
4545
{
@@ -77,7 +77,7 @@
7777
"metadata": {},
7878
"source": [
7979
"```bash\n",
80-
"git log --oneline --graph master\n",
80+
"git log --oneline --graph main\n",
8181
"```\n",
8282
"\n",
8383
"```\n",
@@ -99,7 +99,7 @@
9999
"cell_type": "markdown",
100100
"metadata": {},
101101
"source": [
102-
"If we now **merge** carollian into master, the final state will include both changes:"
102+
"If we now **merge** carollian into main, the final state will include both changes:"
103103
]
104104
},
105105
{
@@ -129,7 +129,7 @@
129129
"```\n",
130130
"\n",
131131
"```\n",
132-
"* b41f869 Merge branch 'carollian' into master_merge_carollian\n",
132+
"* b41f869 Merge branch 'carollian' into main_merge_carollian\n",
133133
"|\\\n",
134134
"| * 2232bf3 Translate into Caroll's language\n",
135135
"* | 2a74d89 Dancing\n",
@@ -150,7 +150,7 @@
150150
"metadata": {},
151151
"source": [
152152
"``` bash\n",
153-
"git log --oneline --graph master_rebase_carollian\n",
153+
"git log --oneline --graph main_rebase_carollian\n",
154154
"```\n",
155155
"\n",
156156
"```\n",
@@ -169,7 +169,7 @@
169169
"To trigger the rebase, we did:\n",
170170
" \n",
171171
"``` bash\n",
172-
"git checkout master\n",
172+
"git switch main\n",
173173
"git rebase carollian\n",
174174
"```\n",
175175
"\n",
@@ -190,8 +190,8 @@
190190
"we get:\n",
191191
"\n",
192192
"```bash\n",
193-
"git checkout carollian\n",
194-
"git merge master\n",
193+
"git switch carollian\n",
194+
"git merge main\n",
195195
"```\n",
196196
"\n",
197197
"\n",
@@ -202,7 +202,7 @@
202202
" 1 file changed, 1 insertion(+)\n",
203203
"```\n",
204204
"\n",
205-
"The master branch was already **rebased on** the carollian branch, so this merge was just a question of updating *metadata* (moving the label for the carollian branch so that it points to the same commit master does): a \"fast forward\".\n",
205+
"The main branch was already **rebased on** the carollian branch, so this merge was just a question of updating *metadata* (moving the label for the carollian branch so that it points to the same commit main does): a \"fast forward\".\n",
206206
"\n",
207207
"### Rebasing pros and cons\n",
208208
"\n",

ch02git/14Bisect.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@
235235
"%%bash\n",
236236
"git bisect start\n",
237237
"git bisect bad # We know the current state is broken\n",
238-
"git checkout master\n",
239-
"git bisect good # We know the master branch state is OK"
238+
"git switch main\n",
239+
"git bisect good # We know the main branch state is OK"
240240
]
241241
},
242242
{
@@ -440,7 +440,7 @@
440440
"%%bash\n",
441441
"git bisect start\n",
442442
"git bisect bad HEAD # We know the current state is broken\n",
443-
"git bisect good master # We know master is good\n",
443+
"git bisect good main # We know main is good\n",
444444
"git bisect run python squares.py 2 &> gitbisect.out\n",
445445
"cat gitbisect.out"
446446
]

0 commit comments

Comments
 (0)