Skip to content
Snippets Groups Projects
Commit 7b97a94c authored by Laurent Heirendt's avatar Laurent Heirendt :airplane:
Browse files

Merge branch 'develop' into 'master'

Regular merge of develop

See merge request R3school/git.slides!35
parents 422c8b34 197ae254
No related branches found
No related tags found
2 merge requests!38Adding additional information about the MATLAB test commands,!35Regular merge of develop
Pipeline #8461 passed
Showing
with 278 additions and 313 deletions
# Git Training
## Dependencies
- node
- yeoman
- bower
- grunt
## Installation
- Update your system
```bash
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential openssl libssl-dev curl
```
- Install Node
```bash
sudo apt install npm
npm install --global npm@latest
```
- Under Unix, create a symbolic link for `node`
```bash
sudo ln -s /usr/bin/nodejs /usr/bin/node
```
- Install Yeoman, bower and grunt
```bash
sudo npm install --global yo
sudo npm install -g generator-reveal
sudo npm install -g grunt-cli
sudo npm install -g bower
```
- Move to the cloned repository and install other dependencies
```bash
sudo npm install
```
## Serve
```bash
grunt
```
## Adding a new slide:
```bash
$ yo reveal:slide --markdown --attributes --notes "Slide Title"
```
## Publish to Github Pages
```bash
grunt dist
```
Copy the content of the `dist` folder into the `gh-pages` branch of `https://github.com/uni-lu/slides`
Some hyperlinks need to be fixed. To do so edit the `index.html` file and remove all `../` before images location.
# git training
\ No newline at end of file
......@@ -4,11 +4,11 @@
* Work on your <font color="red">own</font> branch (in your own fork), and **not** on `master` and **not** on `develop`
* Do **not push** to `master` or `develop`, but **submit a PR**
* Do **not push** to `master` or `develop`, but **submit a PR/MR**
* Get your code **reviewed** by your peers (submit a PR!)
* Get your code **reviewed** by your peers (submit a PR/MR!)
* Submit a PR **often**!
* Submit a PR/MR **often**!
* `clone` a repository, do not download the `.zip` file.
......
## Branches
## Development scheme
Branch-off within the same repository in order to stay safe!
<br>
Generally, in a repository, there are guidelines for contributing.
<br><br>The master branch
<img src="img/branch-master.png" class="branch-master" />
<div class="fragment">
<br>
A common development scheme is dual with a:
## One branch per feature
- **development** version of the code on `develop`
- **stable** version of the code on `master`
Assume that you want to work on a function for a matrix-vector operation.
```bash
$ git checkout -b matrix_vect_mult_myName
# creates the branch locally
```
The `-b` flag creates the branch.
<br>
A **version** of the code is referred to as a **branch**.
<img src="img/branch-create.png" class="branch-create" />
<div class="fragment">
<br><br>
(Live Demo)
Push the branch to the remote repository
```bash
$ git push
```
<br>
<font color="red">In the practice repository, the development branch is called `develop`!</font>
If you do that, `git` might complain
```bash
fatal: The current branch matrix_vect_mult_myName has no upstream branch.
To push the current branch and set the remote as upstream, use
<div class="fragment">
<br>
![bulb](img/bulb.png) Use this dual development scheme for your own repositories!
git push --set-upstream origin matrix_vect_mult_myName
```
## Branches
A **version** of the code (i.e., a **branch**) is made up of a sequence of code changes.
<div class="fragment">
<br>
Follow the advice and do
```bash
$ git push --set-upstream origin matrix_vect_mult_myName
```
These individual code changes are called **commits**.
## Switch between branches
For instance, the `master` and `develop` branches can be represented as a timeline:
<img src="img/branch-master.png" class="branch-master" />
In your terminal, you may see the name of the branch you are on.
List available branches of the repository
## Switch between branches
List all branches of the repository with
```bash
$ git branch --list
$ git branch -a
```
Exit by typing `q`. The branch with the ***** is the current branch.
<div class="fragment">
<br>
Checkout another branch
```bash
$ git checkout <branch_name>
$ git checkout branchName
```
<div class="fragment">
<br>
You can switch back to the `master` branch with
You can switch to the `develop` branch with
```bash
$ git checkout master
$ git checkout develop
```
(Live Demo)
<br>
You can use the 5 essential commands as before.
Only difference: you are on your own branch.
## Create your own version
<img src="img/branch-commit.png" class="branch-commit" />
## Merge a branch
If you want your feature on the `develop` or `master` branches,
**submit a MR or a PR** via the Github/Gitlab interface.
Assume that you want to work on a function for adding 2 numbers.
<div class="fragment">
<br>
Use the **interface** to make use of your peers to review your code!
<img src="img/branch-merge.png" class="branch-merge" />
<font color="red">Create a new **branch**!</font>
<br>
Once merged, you can delete the branch via the interface.
```bash
$ git checkout -b add-2-numbers
```
The `-b` flag creates the branch.
## Github interface
<img src="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" style="width: 100px;"/>
Locally, you have your own version now:
<img src="img/branch-create.png" class="branch-create" />
Detailed information is on [help.github.com/articles/creating-a-pull-request/](https://help.github.com/articles/creating-a-pull-request/).
1. Click on **New pull request**
Push your version to your fork:
```bash
$ git push origin add-2-numbers
```
![New pull request](https://help.github.com/assets/images/help/pull_requests/pull-request-start-review-button.png)
<br><br>
2. Compare the branches
![Compare branches](https://help.github.com/assets/images/help/pull_requests/choose-base-and-compare-branches.png)
<ol start="3">
<li>Assign your peer
<br>
![Assigning a peer](https://help.github.com/assets/images/help/issues/issues_assigning_dropdown.png)
</li>
</ol>
<ol start="4">
<li>Submit the PR
![Submit MR](https://help.github.com/assets/images/help/pull_requests/pullrequest-send.png)</li>
</ol>
(Live Demo)
## How do I start working on a repository?
You have to `clone` it first:
```bash
$ git clone git@github.com:userName/myRepo.git myRepo
```
<div class="fragment">
<br>
If you did not configure your SSH key, clone using HTTPS:
```bash
$ git clone https://github.com/userName/myRepo.git myRepo
```
<br>
<div class="fragment">
You will be prompted to enter your credentials.
## How to configure `git`?
```bash
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "first.last@uni.lu"
```
## Test the configuration
Test whether your username and email have been registered
```bash
$ git config --list
```
<br>
This should list the configuration with `user.name` and `user.email`.
## What is an SSH key?
An SSH key is a secure access credential.
## Why do I need an SSH key?
<br>
**Idea**: <br><br>
communicate **securely** with Github/Gitlab **without** entering the username/password.
## How do I get and set my SSH key?
<br>
Check if you already have an SSH key:
```bash
$ ls -al ~/.ssh
```
<br>
If there is a file with an extension `.pub`, you already have an SSH key.
<div class="fragment">
<br><br>
If you don’t have yet an SSH key, you have to generate one:
```bash
$ ssh-keygen -t rsa
```
<br>
Then, add the SSH key to Github/Gitlab (see demo).
......@@ -9,62 +9,44 @@
<br>
or in other words (remember these!):
```bash
$ git pull
$ git pull <remote> <branch>
$ git status
$ git add myFile.txt # example
$ git commit -m "myMessage" # example
$ git push
$ git push <remote> <branch>
```
## Pull the latest version of an existing repository
First, browse to the cloned directory (`git clone [...]`):
```bash
$ cd practice
```
Then, pull the latest revision:
```bash
$ git pull
$ git pull origin add-2-numbers
# Already up to date
```
<div class="fragment">
<br>
Verify its `status` with:
```bash
$ git status
```
## Be safe and create a new branch
(more on branches in a few minutes)
<br><br><br><br><br>
```bash
$ git checkout -b matrix_vect_mult_myName
```
## Modify a file
Modify and rename `addTwoNumbers.m` in the folder `firstCommit`
<br>
Open the file `addTwoNumbers.m` in the folder `firstCommit` using the `Atom` editor (or any other editor).
<br>
Then, rename the function by adding your name (`addTwoNumbers_myName`)
Modify and rename `addTwoNumbers.m` in the folder `src/firstCommit` as `addTwoNumbers_myName`:
<br>
Uncomment the line
```Matlab
% c = a + b
```bash
$ cd src/firstCommit
$ mv addTwoNumbers.m addTwoNumbers_myName.m
```
<br>
Save and rename the file by <font color="red">adding your name</font>
```bash
$ mv firstCommit/addTwoNumbers.m firstCommit/addTwoNumbers_myName.m
Open the file using the `Visual Studio Code` editor (or any other editor)
and correct the line
```Matlab
c = a + b;
```
......
## Forks
You **fork** when you want to work on a public repository or a protected repository.
## What is a `fork`?
<br><br>
Remember:
<div class="fragment">
<img src="img/fork.jpg" class="as-is" />
[//]: <> (http://www.cndajin.com/data/wls/246/22302193.jpg)
## Not really ...
<img src="img/fork-crossed.png" class="as-is" />
## What is a `fork`?
In general, when contributing to a repository, you only have **read** access.
<div class="fragment">
In other words, you can only **pull** (unless it is your own repository or access has been granted).
<div class="fragment">
<br>
In general, you **cannot write** changes. In other words, you do not have **push** access.
- A **fork** is your own **copy** of a repository.
- A **fork** can have multiple **branches**.
- A **fork** is not a **branch**, but can have multiple **branches**.
<div class="fragment">
You have to work on your **own copy**.
<br><br>
A **fork** is only useful when you want to contribute, e.g., to The COBRAToolbox.
<div class="fragment">
<br>
In other words, you have to work on your own <font color="red">**fork**</font>.
## Fork via interface
## How to get a fork?
Browse to the original repository and click on the button `Fork`
Browse to the original repository and click on the button `Fork`:
![Fork the repo](https://help.github.com/assets/images/help/repository/fork_button.jpg)
(Live Demo)
## Clone your fork
Clone first
```bash
$ git clone https://git-r3lab.uni.lu/myGroup/myRepo.git forkMyRepo
```
## Time to practice!
(Live Demo)
<br>
then, you can change to the directory
```bash
$ cd forkMyRepo
```
Fork the practice repository: <br><br>
https://git-r3lab.uni.lu/R3school/git.practice
## Add the address of the original repository
Then, clone your fork to your home directory!
Add the `upstream` address (original/protected repository)
<div class="fragment">
<br>
```bash
$ git remote add upstream https://git-r3lab.uni.lu/origGroup/origRepo.git
$ git clone ssh://git@git-r3lab-server.uni.lu:8022/yourUserName/
git.practice.git practice
```
<br>
You can then check whether the remote address is set correctly
Change to the practice directory with:
```bash
$ git remote -v
$ cd practice
```
<!-- <img src="img/remote-0-master.png" class="as-is" /> //-->
<!-- <img src="img/remote-1-remote.png" class="as-is" /> //-->
<!--- <img src="img/remote-2-push.png" class="as-is" /> //-->
## Synchronize your fork
<font color="red">
Any other rudimentary method such as
```bash
$ git checkout master
$ git status
```
*'I simply download the `.zip` and unzip it - works like a charm!'*
<div class="fragment">
<br>
Fetch the changes from upstream (similar to pull)
```bash
$ git fetch upstream
```
shall **be avoided**!
</font>
<div class="fragment">
<br>
Merge the retrieved changes
```bash
$ git merge upstream/master
```
<br>Why?
<div class="fragment">
<br>
Push the changes to your own fork
```bash
$ git push origin master
```
## How to update my fork?
As you have your own fork, it will not automatically update once the original repository is update.
## Pull/Merge Requests
![bulb](img/bulb.png) You have to update it yourself!
**Good news!**
<div class="fragment">
<br>
**More on that later!**
Same procedure as with merging a branch...
slides/img/branch-create.png

56.2 KiB | W: | H:

slides/img/branch-create.png

108 KiB | W: | H:

slides/img/branch-create.png
slides/img/branch-create.png
slides/img/branch-create.png
slides/img/branch-create.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
slides/img/branch-master.png

65.4 KiB | W: | H:

slides/img/branch-master.png

92.3 KiB | W: | H:

slides/img/branch-master.png
slides/img/branch-master.png
slides/img/branch-master.png
slides/img/branch-master.png
  • 2-up
  • Swipe
  • Onion skin
slides/img/bulb.png

4.72 KiB

slides/img/fork-crossed.png

1.71 MiB

File added
slides/img/fork.graffle/image1.tiff

1.75 MiB

slides/img/fork.graffle/image2.tiff

257 KiB

slides/img/fork.jpg

35.2 KiB

## Installation
## Installation of `git`
<img src="img/github_app.png" class="as-is" height="200" />
**Linux (Ubuntu)**
```bash
$ sudo apt-get install git-all
```
<br>
**macOS**
Install *Xcode Command Line Tools*
......@@ -17,8 +11,15 @@ Install *Xcode Command Line Tools*
Install Git Bash: <br>`https://git-scm.com/download/win`
<br>
**Linux (Ubuntu)**
```bash
$ sudo apt-get install git-all
```
## How to start?
## How to get started?
**Linux (Ubuntu)** and **macOS**
......@@ -30,84 +31,9 @@ Start the `Terminal` or `iTerm`.
Start `GUI Bash`.
## How to configure `git`?
```bash
$ git config --global user.name "Firstname Lastname"
$ git config --global user.email "first.last@uni.lu"
```
## Does it work?
## Is `git` properly installed?
```bash
$ git --version
# git version 2.10.0
```
## Test the configuration
Test whether your username and email have been registered
```bash
$ git config --list
```
<br>
This should list the configuration with `user.name` and `user.email`.
## How to set my SSH key?
Check if you already have an SSH key:
```bash
$ ls -al ~/.ssh
```
If there is a file with an extension `.pub`, you already have an SSH key.
<div class="fragment">
<br><br>
If you don’t have yet an SSH key, you have to generate one:
```bash
$ ssh-keygen -t rsa
```
<br>
Then, add the SSH key to Github/Gitlab (see demo).
## How do I `clone` a repository?
You can clone a repository with
```bash
$ git clone git@github.com:userName/myRepo.git myRepo
```
<br>
If you did not configure your SSH key, clone using HTTPS:
```bash
$ git clone https://github.com/userName/myRepo.git myRepo
```
<br>
You may be prompted to enter your credentials.
## Clone the practice repository
(Live Demo)
<br>
Clone the training repository! <br><br>
https://git-r3lab.uni.lu/R3.training/git.practice
<div class="fragment">
<br><br>
Any other rudimentary method such as
*'I simply download the `.zip` un unzip it - works like a charm!'*
shall **be avoided**!
```
\ No newline at end of file
......@@ -29,6 +29,12 @@
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "installation.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "github_gitlab.md",
"attr": {
......@@ -36,13 +42,19 @@
}
},
{
"filename": "installation.md",
"filename": "configuration.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "essential_commands.md",
"filename": "cloneRepo.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "forks.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
......@@ -53,6 +65,24 @@
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "essential_commands.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "merge.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "syncFork.md",
"attr": {
"data-background": "img/whiteBG.jpg"
}
},
{
"filename": "best_practices.md",
"attr": {
......
## Merge a branch
If you want your feature on the `develop` or `master` branches,
**submit a MR or a PR** via the Github/Gitlab interface.
<br>
Use the **interface** to make use of your peers to review your code!
<img src="img/branch-merge.png" class="branch-merge" />
<br>
Once merged, you can delete the branch via the interface.
## Github interface
<img src="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" style="width: 100px;"/>
Detailed information is on [help.github.com/articles/creating-a-pull-request/](https://help.github.com/articles/creating-a-pull-request/).
1. Click on **New pull request**
![New pull request](https://help.github.com/assets/images/help/pull_requests/pull-request-start-review-button.png)
<br><br>
2. Compare the branches
![Compare branches](https://help.github.com/assets/images/help/pull_requests/choose-base-and-compare-branches.png)
<ol start="3">
<li>Assign your peer
<br>
![Assigning a peer](https://help.github.com/assets/images/help/issues/issues_assigning_dropdown.png)
</li>
</ol>
<ol start="4">
<li>Submit the PR
![Submit MR](https://help.github.com/assets/images/help/pull_requests/pullrequest-send.png)</li>
</ol>
## Ready to practice?
<br>Go to https://git-r3lab.uni.lu/R3.training/git.practice
<br>And follow the instructions in the `README` file.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment