-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
91 lines (67 loc) · 2.64 KB
/
index.Rmd
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
80
81
82
83
84
85
86
87
88
89
90
91
---
title: "Git Workshop"
author: "Pau Balaguer - pbalaguer@irblleida.cat<br />Jordi Vilaplana - jvilaplana@irblleida.cat"
date: "6/6/2018"
output:
html_document:
theme: united # many options for theme, this one is my favorite.
highlight: tango
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r init, echo=FALSE}
htmltools::img(src = knitr::image_uri(file.path("gitfire.png")), alt = 'Git Workshop', style = 'position:absolute; top:10px; right:10px; padding:10px; width: 256px;')
```
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:300');
body { font-family: 'Roboto Mono', monospace; }
table.table { width: 100% !important; }
</style>
Git (mini)Workshop for statiticians.
## Prerequisites
Download and install git and create a GitHub account.
- [git](https://git-scm.com/downloads)
- [GitHub Account](https://github.com/)
## Git Basics
Basic git commands.
| Command | Description |
| ------- | ----------- |
| `git init` | Create a new local repository. |
| `git clone` | Clone an existing repository. |
| `git add -A` | Stage (add) all changed files, ready for commit. |
| `git status` | List new or modified files not yet commited. |
| `git commit -a` | Commit all local changes in tracked files. |
| `git commit` | Commit previously staged files. |
| `git push` | Publish local changes to GitHub. |
| `git pull` | Download changes from GitHub. |
## Proposed git workflow
### Start
1. [Create a new repository](https://github.com/organizations/IRBLleida/repositories/new) on GitHub.
2. Checkout the newly created repository in RStudio via `File - New Project ...`.
3. Add `.DS_Store` to the `.gitignore` file.
4. Make changes.
5. Stage and `commit` changes.
6. `push` changes.
<hr />
>
> Whenever I see a door that says "push", I always pull first, to avoid conflicts.
>
<hr />
### Work
1. `pull` changes (this will avoid possible conflicts).
2. Make changes.
3. Stage and `commit` changes.
4. `push` changes.
The `push` will fail if someone has pushed changes after your last `pull`. In this case, we got ourselves a conflict.
![](push-fail.png)
To resolve it, after the failed `push` do:
5. `pull` changes.
RStudio will try to resolve the conflicts automatically. However, if in both versions there are changes to the same lines of the file, RStudio will ask you to resolve these conflicts manually. To do this, you will need to manually check your file and modify it as you wish. When you are done, do:
![](pull-conflicts.png)
6. Stage and `commit` changes.
7. `push` changes.
<hr />
<div style="width: 70%; margin-left: auto; margin-right: auto;">
![](git-commits.png)
</div>