branches.md 1.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
## Development scheme

<br>
Generally, in a repository, there are guidelines for contributing.

<div class="fragment">

<br>
A common development scheme is dual with a:

- **development** version of the code on `develop`
- **stable** version of the code on `master`

<br>
A **version** of the code is referred to as a **branch**.

<div class="fragment">
<br><br>
Laurent Heirendt's avatar
Laurent Heirendt committed
19
<img src="img/icon-live-demo.png" height="100px">
20
21
22
23
24
25
26
27
28
29


<br>
<font color="red">In the practice repository, the development branch is called `develop`!</font>

<div class="fragment">
<br>
![bulb](img/bulb.png) Use this dual development scheme for your own repositories!


Laurent Heirendt's avatar
Laurent Heirendt committed
30
## Branches
31

Laurent Heirendt's avatar
Laurent Heirendt committed
32
A **version** of the code (i.e., a **branch**) is made up of a sequence of code changes.
33
34
35

<div class="fragment">
<br>
Laurent Heirendt's avatar
Laurent Heirendt committed
36
These individual code changes are called **commits**.
37
38


Laurent Heirendt's avatar
Laurent Heirendt committed
39
For instance, the `master` and `develop` branches can be represented as a timeline:
40
41
42
43

<img src="img/branch-master.png" class="branch-master" />


Laurent Heirendt's avatar
Laurent Heirendt committed
44
## Switch between branches
45

Laurent Heirendt's avatar
Laurent Heirendt committed
46
List all branches of the repository with
47
```bash
Laurent Heirendt's avatar
Laurent Heirendt committed
48
$ git branch -a
49
50
```

Laurent Heirendt's avatar
Laurent Heirendt committed
51
Exit by typing `q`. The branch with the ***** is the current branch.
52

Laurent Heirendt's avatar
Laurent Heirendt committed
53
54
55
<div class="fragment">
<br>
Checkout another branch
56
```bash
Laurent Heirendt's avatar
Laurent Heirendt committed
57
$ git checkout branchName
58
59
```

Laurent Heirendt's avatar
Laurent Heirendt committed
60
<div class="fragment">
61
<br>
Laurent Heirendt's avatar
Laurent Heirendt committed
62
You can switch to the `develop` branch with
63
```bash
Laurent Heirendt's avatar
Laurent Heirendt committed
64
$ git checkout develop
65
66
```

Laurent Heirendt's avatar
Laurent Heirendt committed
67
68
69
<div class="fragment">
<br>
<img src="img/icon-live-demo.png" height="100px">
70
71


Laurent Heirendt's avatar
Laurent Heirendt committed
72
## Create your own version
73

74
Assume that you want to work on a function for adding 2 numbers.
Laurent Heirendt's avatar
Laurent Heirendt committed
75

76
77
<div class="fragment">
<br>
Laurent Heirendt's avatar
Laurent Heirendt committed
78
<font color="red">Create a new **branch**!</font>
79
80

```bash
81
$ git checkout -b add-2-numbers
82
```
Laurent Heirendt's avatar
Laurent Heirendt committed
83
The `-b` flag creates the branch.
84

85
86

Locally, you have your own version now:
Laurent Heirendt's avatar
Laurent Heirendt committed
87
88
<img src="img/branch-create.png" class="branch-create" />

89
90

Push your version to your fork:
91
```bash
92
$ git push origin add-2-numbers
93
94
```

Laurent Heirendt's avatar
Laurent Heirendt committed
95
96
97
98
<br>
<div class="fragment">
<br>
<img src="img/icon-live-demo.png" height="100px">