-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path04_git_basics.Rmd
125 lines (83 loc) · 2.01 KB
/
04_git_basics.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
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
---
title: "Git Basics"
author: "Dietmar Rieder, Gregor Sturm"
output:
ioslides_presentation: default
---
## What is Git?
* Source code management (SCM) tool
* Developed by Linus Torvalds for the Linux kernel
* Keep track of source code in *commits* and *branches*
* *Commit = “unit of code change”*
![](images/branch-model.png)
## Why should I use git?
* Backup your code
* Synchronize between laptop and HPC
* Know what you did 2 months ago
<br />
> - Git is an industry standard
> - Collaborate with others
> - Share your code
## A git repository...
...is just a folder with a special `.git` directory.
<br />
Create a repository by typing
```bash
git init
```
within a directory.
## The four git states
```{r, fig.cap="Figure from http://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository", echo=FALSE}
knitr::include_graphics("images/git-states.png")
```
## The four git states
Display modified files and their states:
```bash
git status
git diff
```
Add a modified file to the *staging area*:
```bash
git add <FILE>
```
Commit all *staged* files:
```bash
git commit
```
Browse history
```bash
git log
```
## Working with branches
List branches
```
git branch -v
```
Create a new branch from current commit
```
git branch <NAME>
```
Switch to another branch
```
git switch <NAME>
```
## Ignoring files
Create a file named `.gitignore` in the git repository.
Example:
```
.Rhistory
.RData
*.nb.html
plots/*.pdf
```
## Configuring git
Configuration file at `~/.gitconfig`. Modify with text-editor or with `git config` command.
When collaborating online, it is important to set your identity -- it will be associated with every commit:
```bash
git config --global user.name "Your name"
git config --global user.email "[email protected]"
```
## Links
* [ICBI Gitlab (for internal projects)](gitlab.i-med.ac.at)
* [ICBI GitHub (for published projects)](github.com/icbi-lab)
* [Git Cheatsheet by GitLab](https://about.gitlab.com/images/press/git-cheat-sheet.pdf)