generated from allisonhorst/meds-distill-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
day1-github_branches.qmd
79 lines (48 loc) · 2.91 KB
/
day1-github_branches.qmd
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
---
title: "Collaborative Coding Workflows: Branching"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Collaborating through write / push access
When you collaborate closely and actively with colleagues, you do not want necessarily to have to review all their changes through pull requests. You can then give them write access (`git push`) to your repository to allow them to directly edit and contribute to its content. This is the workflow we will recommend to use within your working group.
#### Adding collaborators to a repository
* Click on the repository
* On the top tabs, click ![](img/github-repo-settings.png)
* On the left pane, click `Manage access` and click on "Invite a Collaborator" to enter the usernames you want to add
![collaborators](img/github-collaborators.png)
Under this collaborative workflow, we recommend to use git `branches` combined with pull requests to avoid conflicts and to track and discuss collaborators contributions.
# Branches
![adapted from https://www.atlassian.com/git/tutorials/git-merge](img/atlassian_branches_sketch.png)
What are branches? Well in fact nothing new, as the `main` is a branch. A branch represents an independent line of development, parallel to the main (branch).
Why should you use branches? For 2 main reasons:
* We want the main to only keep a version of the code that is working
* We want to version the code we are developing to add/test new features (for now we mostly talk about feature branch) in our script without altering the version on the main.
## Working with branches
### Creating a new branch
In RStudio, you can create a branch using the git tab.
1. Click on the branch button
```{r RStudio git pane branch, out.width='60%', fig.align='center', echo = FALSE}
knitr::include_graphics("img/rstudio-git-branch-create.png")
```
2. Fill the branch name in the new branch window; in this example, we are going to use `test` for the name; leave the other options as default and click create
```{r RStudio git new branch window, out.width='40%', fig.align='center', echo = FALSE}
knitr::include_graphics("img/rstudio-git-branch-test.png")
```
3. you will be directly creating a local and remote branch and switch to it
```{r RStudio git new branch, out.width='62%', fig.align='center', echo = FALSE}
knitr::include_graphics("img/rstudio-git-branch-new.png")
```
Congratulations you just created your first branch!
Let us check on Github:
```{r RStudio github new branch, out.width='45%', fig.align='center', echo = FALSE}
knitr::include_graphics("img/github-new-branch.png")
```
As you can see, now there are two branches on our remote repository:
- main
- test
### Using a branch
Here there is nothing new. The workflow is exactly the same as we did before, except our commits will be created on the `test` branch instead of the main branch.
## Hands-on
Let's practice this by team of 2!!
<https://github.com/brunj7/eds214-handson-ghcollab>