Skip to content

Commit 19de210

Browse files
committed
Move 3-github to pycalc
1 parent 8c45c8b commit 19de210

File tree

1 file changed

+68
-44
lines changed

1 file changed

+68
-44
lines changed

3-github.md

+68-44
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ flag:
4040

4141
```console
4242
$ git remote -v
43-
origin [email protected]:jni/r-string-calc (fetch)
44-
origin [email protected]:jni/r-string-calc (push)
43+
origin [email protected]:jni/pycalc (fetch)
44+
origin [email protected]:jni/pycalc (push)
4545
```
4646

4747
That tells both the name of the remote, *and its location*. "origin" is
@@ -60,25 +60,48 @@ Delta compression using up to 4 threads.
6060
Compressing objects: 100% (36/36), done.
6161
Writing objects: 100% (36/36), 3.33 KiB | 0 bytes/s, done.
6262
Total 36 (delta 25), reused 0 (delta 0)
63-
To [email protected]:jni/r-string-calc
63+
To [email protected]:jni/pycalc
6464
8ab0457..8de6fb7 master -> master
6565
```
6666

6767
Read the above as "push to "origin" my branch "master" onto its branch
68-
"master".
68+
"master". Branches are managed locally for each repository, so the branch names
69+
don't actually have to match. That is, we could easily have written:
6970

70-
After this, you'll be able to refresh your repo page on GitHub and
71+
```console
72+
$ git push origin master:other-branch-name
73+
```
74+
75+
and then the contents of our branch `master` locally would be mirrored in the
76+
remote branch `other-branch-name` on `origin`. In order to tell git to keep
77+
track of matching branch names, use the option `--set-upstream`:
78+
79+
```console
80+
$ git push origin --set-upstream master
81+
```
82+
83+
This tells git: "push `master` onto `origin`'s `master`, and note that they are
84+
mirrors of each other." This means that later, we only need to do:
85+
86+
```console
87+
$ git push origin
88+
```
89+
90+
And git will know that `master` goes onto `origin`'s `master`.
91+
92+
After this, you'll be able to refresh your page on GitHub and
7193
browse your code's history.
7294

7395
## Exercise 4: GitHub pull requests
7496

7597
For this exercise you will have to pair up with your neighbour, which
7698
we will name Alice. (And your name is Bob, in keeping with the computer
77-
science literature.)
99+
science literature.) Decide now who will be Bob and who will be Alice in the
100+
pair.
78101

79-
Delete your "r-string-calc" repository on GitHub (this is done under "Settings"
80-
in the right-hand menu). You've realised that Alice has her own version and
81-
that you can both save effort by collaborating on this project.
102+
As Bob, you should delete your "pycalc" repository on GitHub (this is done
103+
under "Settings" in the right-hand menu). You've realised that Alice has her
104+
own version and that you can both save effort by collaborating on this project.
82105

83106
You've been wanting to do some arithmetic on some data, but the first
84107
number you need to add is often a decimal number. In those cases, the
@@ -88,39 +111,41 @@ You want to modify it so that the first number is allowed to be a decimal
88111
number.
89112

90113
Navigate to Alice's repository on GitHub
91-
(https://github.com/[Alice's username]/r-string-calc), and click the "Fork"
114+
(https://github.com/[Alice's username]/pycalc), and click the "Fork"
92115
button.
93116
This will create a copy of Alice's repo on your GitHub account, which
94117
you can then clone on your machine as before. But note that you need to
95-
delete your existing repository! Instructions below (some of the directories
96-
and obviously the "bob" username needs to be changed to yours!):
118+
delete your existing work, or git will complain! Instructions below (some of
119+
the directories and obviously the "bob" username needs to be changed to
120+
yours!):
97121

98122
```console
99123
$ pwd
100-
/Users/bob/projects/r-string-calc
124+
/Users/bob/projects/pycalc
101125
$ cd ..
102-
$ rm -rf r-string-calc
103-
$ git clone [email protected]:bob/r-string-calc.git
104-
$ cd r-string-calc
105-
$ git checkout -b decimals
126+
$ rm -rf pycalc
127+
$ git clone [email protected]:alice/pycalc
128+
$ cd pycalc
129+
$ git switch --create decimals
106130
```
107131

108-
Edit the `strcalc.R` file so that `num0` is converted with `as.numeric`
109-
instead of `as.integer`.
132+
Edit the `calc.py` file so that `num0` is converted with `float`
133+
instead of `int`. (Leave `num1` unchanged for now.)
110134

111135
Now commit those changes and push them *to a new branch on GitHub*. If you use
112136
the `--set-upstream` flag, you tell git to create a branch with the same
113137
name that "tracks" the current branch. This makes future pushes easier.
114138

115139
```console
116-
$ git add strcalc.R
140+
$ git add calc.py
117141
$ git commit -m "Allow num0 to be any decimal number"
118142
$ git push origin --set-upstream decimals
119143
```
120144

121145
Go to the GitHub page for the project. You should see a new button
122146
showing that you've recently updated a branch and prompting you to
123-
*initiate a pull request*.
147+
*initiate a pull request*. (You can also copy the "new pull request" address
148+
from git's message when you push.)
124149

125150
Here's how this works: you don't know Alice. You probably have never met
126151
her. So it's natural that you can't just push random stuff willy-nilly to her
@@ -131,7 +156,7 @@ changes, you ask *her* to *pull* from your own history.
131156
The PR will tell Alice that you've made some
132157
changes to the code and you would like her to incorporate them into
133158
her project. Notice that you did this *without needing any special
134-
access from Alice!* This is the magic of GitHub.
159+
access from Alice!* This is the magic of GitHub and open source.
135160

136161
Check out the impact that GitHub has had on a few open source Python projects:
137162

@@ -153,30 +178,28 @@ title and message here is very important!
153178
> When in Rome, do as the Romans do. Look at their existing codebase
154179
> and try to follow their example. (This is not to say that you can't
155180
> improve on it; but make sure your documentation and testing *at least*
156-
> least meets their standards.)
157-
181+
> meets their standards.
158182
159183

160184
Alice should get an email notification that there is a pull request to
161185
her project. Clicking on it, she will be taken to the web form for the
162-
PR, where she can examine the changes that Bob has made (the "Files changed"
163-
tab).
186+
PR, where she can examine the changes that Bob has made (the "Files" tab).
164187

165188
Alice will note that this great change would be made much more useful if it
166-
also used `as.numeric` for `num1`! She comments on the
189+
also used `float` for `num1`! She comments on the
167190
PR page: "This is a great addition, thanks! Could you please do the same for
168191
num1?"
169192

170193
On his machine, Bob makes the requested change, commits, and pushes his changes:
171194

172195
```console
173-
$ # ... edit strcalc.R ...
174-
$ git add strcalc.R
175-
$ git commit -m "Use as.numeric for num1's conversion also"
196+
$ # ... edit calc.py ...
197+
$ git add calc.py
198+
$ git commit -m "Use float for num1's conversion also"
176199
$ git push # no need to specify repo or branch anymore, having `set-upstream`
177200
```
178201

179-
If both Bob and Alice go back to the PR page, they will see that the PR has
202+
If either Bob or Alice go back to the PR page, they will see that the PR has
180203
been automagically updated with Bob's new changes! (Though they may need to
181204
refresh the page.)
182205

@@ -194,28 +217,29 @@ For this, he needs to add it to his list of remotes (remember remotes?):
194217

195218
```console
196219
$ git remote -v
197-
origin [email protected]:bob/r-string-calc (fetch)
198-
origin [email protected]:bob/r-string-calc (push)
199-
$ git remote add upstream [email protected]:alice/r-string-calc
220+
origin [email protected]:bob/pycalc (fetch)
221+
origin [email protected]:bob/pycalc (push)
222+
$ git remote add upstream [email protected]:alice/pycalc
200223
$ git remote -v
201-
origin [email protected]:bob/r-string-calc (fetch)
202-
origin [email protected]:bob/r-string-calc (push)
203-
upstream [email protected]:alice/r-string-calc (fetch)
204-
upstream [email protected]:alice/r-string-calc (push)
205-
$ git checkout master
224+
origin [email protected]:bob/pycalc (fetch)
225+
origin [email protected]:bob/pycalc (push)
226+
upstream [email protected]:alice/pycalc (fetch)
227+
upstream [email protected]:alice/pycalc (push)
228+
$ git switch master
206229
$ git pull upstream master # get upstream's master branch, and merge
230+
$ git push origin master
207231
```
208232

209233
Bob can now inspect his history log and see that both his changes and Alice's
210-
merge are there. Use GitX for this or the `lsd` alias we learned earlier, or
211-
a simple git-log will also do.
234+
merge are there. Use GitKraken/GitX/GitTower/other GUI for this, or the `lsd`
235+
alias we learned earlier, or a simple git-log will also do.
212236

213237
## Bonus exercise 1: self-PRs and code review
214238

215239
Do the reverse approach, which is a bit different. Alice has gained a
216240
collaborator in Bob. Even though she still maintains control of the project
217-
repository, she wants to enlist his help. She sprouts a branch, adds a line or
218-
two (for example, she might want to add a test function, `test.compute`, that
241+
repository, she wants to enlist his help. She creates a branch, adds a line or
242+
two (for example, she might want to add a test function, `test_compute`, that
219243
runs `compute` for a few known values and makes sure the results match up), then
220244
*creates a PR against her own repository.* She then asks Bob to review her
221245
change by mentioning his username (e.g. `@bob`, as in Twitter) in a comment on
@@ -243,7 +267,7 @@ The common solution is to *rebase*, that is, to replay the changes on Bob's
243267
branch on top of the latest `master` from Alice's repository.
244268

245269
```console
246-
$ git checkout master
270+
$ git switch master
247271
$ git pull upstream master
248272
$ git rebase master test-2
249273
```

0 commit comments

Comments
 (0)