diff --git a/images/name_branch.png b/images/name_branch.png new file mode 100644 index 0000000..7dace02 Binary files /dev/null and b/images/name_branch.png differ diff --git a/images/new_branch.png b/images/new_branch.png new file mode 100644 index 0000000..8e0cca1 Binary files /dev/null and b/images/new_branch.png differ diff --git a/index.Rmd b/index.Rmd index 92c886c..8af2293 100644 --- a/index.Rmd +++ b/index.Rmd @@ -695,15 +695,34 @@ Well done! Now the other team members will need to pull down this new commit mer ### Exercise 6: The tree of git, or the basics of branching -A great way to make conflicst much more manageable is to use the magic of branching. Branches are like alternate timelines that allow you to work on a snapshot of the repo at a given time. You start by "branching out of the main branch": this copies the current version of the repo and allows you to make changes on a separate "branch". +A great way to make conflicst avoidable is to use the magic of branching. Branches are like alternate timelines that allow you to work on a snapshot of the repo at a given time. You start by "branching out of the main branch": this copies the current version of the repo and allows you to make changes on a separate "branch". -One of the team members should do the following. The first thing is to create the branch: +The first thing is to create the branch: + +#### At the terminal ```{bash eval=FALSE, include=TRUE} git branch mynewbranch # This simply creates the new branch ``` -The branch is created, but you are still on the main branch. To be able to switch to the new branch, we need to "checkout' the branch: +#### In Rstudio + +1. Click on the new branch button in the top right corner of the git pane. + +
+ ![](images/new_branch.png) +
+ +2. Name the branch and create it. Make sure the remote origin is checked. + +
+ ![](images/name_branch.png) +
+ +*** +> The branch is created, but you are still on the main branch. To be able to switch to the new branch, we need to "checkout' the branch. + +#### At the terminal ```{bash eval=FALSE, include=TRUE} git checkout mynewbranch # This makes you switch to the new branch @@ -723,7 +742,16 @@ nothing to commit, working tree clean ``` ***note***: *there is a shortchut to do those 2 commands in one line: `git checkout -b mynewbranch`* -You are now on the new branch! This branch is only on your local machine for now. Let's add some changes and then commit and push so that you branch is saved on the remote! + +#### In Rstudio + +Rstudio **automatically checks out the new branch when your create it**. You can switch branches veru easily by using the drop down menu in the git pane (find it by clicking on whatever branch name is shown in git pane). + +*** + +> You are now on the new branch! This branch is only on your local machine for now. Let's add some changes and then commit and push so that you branch is saved on the remote! + +#### At the terminal ```{bash eval=FALSE, include=TRUE} # Do some changes in your repo! They will only be part of the commit hostory of your branch @@ -754,6 +782,10 @@ To github.com:VLucet/gitWorkshop.git * [new branch] mynewbranch -> mynewbranch ``` +#### In Rstudio + +[...] + Awesome! Now, while one of the team member is adding commits to their new branch, someone else should keep adding changes to the main branch. Once this is done, it is time to merge the new branch with the main branch. Merging means doing a "pull request": you are pulling the new branch into the main branch. You therefore need to checkout the main branch and then *pull* the new branch into the main. diff --git a/index.html b/index.html index 6e66c79..bf5094d 100644 --- a/index.html +++ b/index.html @@ -711,16 +711,50 @@

In Rstudio

Exercise 6: The tree of git, or the basics of branching

-

A great way to make conflicst much more manageable is to use the magic of branching. Branches are like alternate timelines that allow you to work on a snapshot of the repo at a given time. You start by “branching out of the main branch”: this copies the current version of the repo and allows you to make changes on a separate “branch”.

-

One of the team members should do the following. The first thing is to create the branch:

+

A great way to make conflicst avoidable is to use the magic of branching. Branches are like alternate timelines that allow you to work on a snapshot of the repo at a given time. You start by “branching out of the main branch”: this copies the current version of the repo and allows you to make changes on a separate “branch”.

+

The first thing is to create the branch:

+
+

At the terminal

git branch mynewbranch      # This simply creates the new branch
-

The branch is created, but you are still on the main branch. To be able to switch to the new branch, we need to "checkout’ the branch:

+
+
+

In Rstudio

+
    +
  1. Click on the new branch button in the top right corner of the git pane.
  2. +
+
+ +
+
    +
  1. Name the branch and create it. Make sure the remote origin is checked.
  2. +
+
+ +
+
+
+

The branch is created, but you are still on the main branch. To be able to switch to the new branch, we need to "checkout’ the branch.

+
+
+
+

At the terminal

git checkout mynewbranch    # This makes you switch to the new branch
Switched to branch 'mynewbranch'
git status          # You are now on the new branch
On branch mynewbranch
 nothing to commit, working tree clean
-

note: there is a shortchut to do those 2 commands in one line: git checkout -b mynewbranch You are now on the new branch! This branch is only on your local machine for now. Let’s add some changes and then commit and push so that you branch is saved on the remote!

+

note: there is a shortchut to do those 2 commands in one line: git checkout -b mynewbranch

+
+
+

In Rstudio

+

Rstudio automatically checks out the new branch when your create it. You can switch branches veru easily by using the drop down menu in the git pane (find it by clicking on whatever branch name is shown in git pane).

+
+
+

You are now on the new branch! This branch is only on your local machine for now. Let’s add some changes and then commit and push so that you branch is saved on the remote!

+
+
+
+

At the terminal

# Do some changes in your repo! They will only be part of the commit hostory of your branch
 git commit -a -m 'added some changes to the new branch'  # Another shorcut to add and commit at the same time!
[mynewbranch 92b76fb] added some changes to the new branch
@@ -738,6 +772,10 @@ 

Exercise 6: The tree of git, or the basics of branching

remote: To github.com:VLucet/gitWorkshop.git * [new branch] mynewbranch -> mynewbranch
+
+
+

In Rstudio

+

[…]

Awesome! Now, while one of the team member is adding commits to their new branch, someone else should keep adding changes to the main branch. Once this is done, it is time to merge the new branch with the main branch.

Merging means doing a “pull request”: you are pulling the new branch into the main branch. You therefore need to checkout the main branch and then pull the new branch into the main.

git checkout main   # You've switched to the main branch
@@ -756,6 +794,7 @@

Exercise 6: The tree of git, or the basics of branching

Additionally, you can do all this by creating a pull request on github (DEMO).


+

DEMO: Gitkraken

DEMO of the git client GitKraken if time permits. Otherwise, see this video. This video actually also covers more advanced topics, but you can use it to get a feel for where the interface to find the buttons for adding (staging), committing and pushing/pulling.