Skip to content

Commit 552ed88

Browse files
committed
Branches content
1 parent d6c445d commit 552ed88

8 files changed

Lines changed: 45 additions & 0 deletions

docs/chapters/chapter_04.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,48 @@ That's all done! Have a look on the GitHub website. It's updated with the local
151151

152152
![GitHub website updated](images/github-updated-1.png)
153153

154+
155+
## 4.3 Making branches and collaborating
156+
157+
Now the project is growing, and some colleagues want to work on the code together. Without Git, this would be a slow process, as only one of you can work on the code at a time. Otherwise, it would be difficult to combine the changes.
158+
159+
With Git, however, code collaboration can work very efficiently. This is achieved by branching, merging and pull requests.
160+
161+
### Editing on a new branch
162+
163+
As explained in Chapter 3 and 5, the purpose of *branches* is to separate different strands of work.
164+
165+
Here for example, while your colleague will write some hypothesis tests on the data, you would like to make more plots to visualize data. So, before coding, you create and checkout a branch `visualization`.
166+
167+
> *Checkout* simply means making this the active branch, so that the following edits will be made on this branch.
168+
169+
In GitHub Desktop, click the branch box on the top banner, and click new branch.
170+
171+
![GHD New Branch](images/ghd-new-branch.png)
172+
173+
Enter the new branch name and create.
174+
175+
![GHD Create branch](images/ghd-create-branch-visualization.png)
176+
177+
After switching, the active branch is now `visualization` which can be seen on the top banner.
178+
179+
Alternatively, in PyCharm, create the new branch from the Git menu:
180+
181+
![PyCharm New branch](images/pyc-newbranch.png)
182+
183+
To verify the active branch, look for the Git symbol at the bottom of the screen. Most IDEs have a similar display.
184+
185+
![PyCharm active branch](images/pyc-verify-branch-visualization.png)
186+
187+
Now you can modify the code, without the need to worry about what your colleague is doing. After some hard work in coding, you can stage, commit and push as usual. Everything is saved on the new `visualization` branch.
188+
189+
### Merging and pull requests
190+
191+
When you think you have finished all the codes related to `visualization`, you will want to *merge* this branch back to the base branch (in our case `master`), so that collaborators and users will be able to see and use these codes by default.
192+
193+
To do this, we first open a *pull request*.
194+
195+
Go to the repository webpage on GitHub, and click on the "Pull requests" tab. GitHub likely realizes that you are opening the pull request for the most recent branch, `visualization`. Click the green "Compare & pull request" button.
196+
197+
![Pull requests](images/gh-new-pr.png)
198+

docs/chapters/images/gh-new-pr.png

80.3 KB
Loading
54.7 KB
Loading
42.3 KB
Loading
5.97 KB
Loading
110 KB
Loading
34.2 KB
Loading
44 KB
Loading

0 commit comments

Comments
 (0)