-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_github_workshop.Rmd
More file actions
147 lines (91 loc) · 4.52 KB
/
git_github_workshop.Rmd
File metadata and controls
147 lines (91 loc) · 4.52 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
title: "Git and Github"
subtitle: "Workshop Exercises"
author: 'Tim Beissinger, Elizabeth King, Kevin Middleton, and Lauren Sullivan'
output:
ioslides_presentation:
fig_width: 7
css: styles.css
---
```{r setup, echo=FALSE}
```
## Notes
This workshop was modeled from several tutorials available online and in some cases, took material and quotes directly:
[R packages book section by Hadley Wickham](http://r-pkgs.had.co.nz/git.html)
[Happy Git and Github for the useR by Jenny Bryan](http://happygitwithr.com/)
[git/github guide by Karl Broman](http://kbroman.org/github_tutorial/)
[Version Control with Git from Software Carpentry](http://swcarpentry.github.io/git-novice/)
[Git for Humans by Alice Bartlett](https://speakerdeck.com/alicebartlett/git-for-humans)
Additional Git resources are listed in Karl's guide: [Resources](http://kbroman.org/github_tutorial/pages/resources.html)
## Plan for the workshop
1. Q & A from the lecture
1. Review setting up a personal repository, committing changes, pushing & pulling
1. Setting up a collaborative repository with a small group
Our goal at the end of the day is for you to feel comfortable using git and committed to use git for the projects you are working on now and in the future.
## Questions from the lecture
What questions do you have?
## Review: Creating a repository remotely on GitHub
**Activity**
1. Log in to GitHub.com
1. Click the "New Repository" button (under the `+` icon in the menu bar)
1. Name your repository with your initials and misc (for example EGKmisc) to hold your miscellaneous R functions
1. Clone the repository to your local machine
## Make a change
**Activity**
1. Start a new R script
1. Write a function or a bit of code
1. Save your file with an informative name in your project folder
## Commits
When you are happy with some work you've done and want to take a snapshot, you will do what is called a commit.
**Activity**
1. Stage your files
1. Commit them with a message like "add function to calculate mean"
Write informative commit messages. Your future self will appreciate it.
## Syncing: Push and Pull
What we've done so far is take a snapshot locally on our machine. To interact with the remote, we need push and pull.
- Push = moving local changes to the remote
- Pull = moving from remote to local
**Activity**
1. Push your last commit to GitHub
1. Go to github.com and see that your commit is there.
## Collaborating with others
- Collaboration is one of the main reasons to learn git
- Adding collaborators to your projects
- Collaborating with others' projects
**Activity**
1. Form a collaboration with 1-2 other people in the workshop
1. The project leader should create a new repository on GitHub
1. The project leader should add their collaborators
1. Everyone should clone the repository
## Good collaboration
- The first rule of good collaboration using git is to *always pull before making changes*. Let's practice this.
**Activity**
1. The repository owner creates a file. Save, stage, commit, and push.
1. The collaborators pull changes. Make new files, save, stage, commit, and push.
1. Everyone pulls to update their local copies.
## Problems, warnings, how to recover
Where do problems come from?
- You or your collaborator makes changes and pushes them. You make changes to the same file(s) without pulling first.
- git will not let you push changes to overwrite other changes
## Bad collaboration
**Activity**
1. One member should change a file, save, stage, commit, and push.
1. Another member should change the same file without pulling first. Now try to commit and push.
1. Observe the result.
## What to do when you run into problems
Your options include:
1. Advanced git tools to resolve the changes
1. Burn it down and start again (often the easier option)
**Activity**
1. The member with the conflict from the previous activity should rename their local copy folder.
1. Clone the repository from the remote copy anew
1. Integrate any changes they've made by hand. Save, stage, commit, and push
## Distributing code: making things reproducible for others
An aspiration for us all is for every project to:
- Have a public GitHub repository
- Include all code and step by step instructions to reproduce all products: results, figures, tables, etc.
> Don't get hung up if you don't do this perfectly every time. Try to do better with each project
## Questions?
<center>
<img src=https://camo.githubusercontent.com/cee307f9e03796326817bee5006325f0c229b913/687474703a2f2f692e696d6775722e636f6d2f5849615a5a326b2e6a7067 width="70%" />
</center>