Newer
Older
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
+++
date = "2018-02-23T15:28:13+01:00"
title = "Get the source code"
author = "Lars Bilke"
weight = 1003
[menu]
[menu.devguide]
parent = "getting-started"
+++
::: {.note}
### Attribution
The content of this page is largely taken from the [GitHub-blog](https://github.com/blog/2042-git-2-5-including-multiple-worktrees-and-triangular-workflows).
:::
## Create a fork
Go to the [official OGS-6 repository](https://github.com/ufz/ogs) and click the "Fork"-button. This creates a new fork under your account with the URL `https://github.com/YOUR-USERNAME/ogs`.
## Setup your local clone
You can use the git command line tool to clone the remote repository on GitHub to your PC:
```bash
$ git clone https://github.com/YOUR-USERNAME/ogs
$ cd ogs
$ git config remote.pushdefault origin
$ git config push.default current
```
This creates a new folder `ogs` in your current working directory with the OGS source code. After this step, the remote called `origin` refers to your fork on GitHub. It also sets the default remote for pushes to be `origin` and the default push behavior to `current`. Together this means that if you just type `git push`, the current branch is pushed to the `origin` remote (git version >= 2.5 required).
Create a second remote called `upstream` that points at the main OGS repository and fetch from it:
```bash
$ git remote add upstream https://github.com/ufz/ogs
$ git fetch upstream
{{< asciinema url="https://asciinema.org/a/249002" speed="3" rows="20" >}}
## Enable git commit hooks
[Git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) help to check for several issues before doing commits or pushes and it is highly recommended to enable these checks.
Install [pre-commit](https://pre-commit.com/) (a git hook manager) via Pythons `pip`:
```bash
pip3 install --user pre-commit
```
Enable the hooks in the source code with:
```bash
cd ogs
pre-commit install
```
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
## Optional: Working on a new feature
You only have to follow the above steps once. From then on, whenever you want to work on a new feature, you can more easily interact with the remote repositories.
Make sure that your local repository is up-to-date with the upstream repository:
```bash
$ git fetch upstream
```
Create a branch `feature-name` off of upstream `master`-branch to work on a new feature, and check out the branch:
```bash
git checkout -b feature-name upstream/master
```
This automatically sets up your local `new-feature`-branch to track the upstream `master`-branch. This means that if more commits are added to `master` upstream, you can merge those commits into your `feature`-branch by typing
```bash
$ git pull
```
or rebase your branch on top of the new master by typing
```bash
$ git pull --rebase
```
Now after you implemented the feature and committed your work you can push the new commits to the `feature-name`-branch on your GitHub fork:
```bash
$ git push
```
If your work is done submit a pull request.
This workflow is summarized with this picture:
