Collaborative Coding Workflows: Branching
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
- On the left pane, click
Manage access
and click on “Invite a Collaborator” to enter the usernames you want to add
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
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.
- Click on the branch button
- 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
- you will be directly creating a local and remote branch and switch to it
Congratulations you just created your first branch!
Let us check on Github:
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!!