Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
R3
school
courses
Commits
0217f4da
Commit
0217f4da
authored
Oct 02, 2019
by
Laurent Heirendt
✈
Browse files
Merge branch '2019-10-03_siu-basic-course' into 'develop'
Basic git course for SIU See merge request
!48
parents
0f9b330e
e50d2dbd
Pipeline
#14504
passed with stage
in 1 minute and 35 seconds
Changes
14
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
2019/2019-10-03_basicGitTraining-SIU/slides/best_practices.md
0 → 100644
View file @
0217f4da
# Best practices
*
`pull`
before
`push`
*
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`
, but
**submit a PR**
*
Get your code
**reviewed**
by your peers (submit a PR!)
*
Submit a PR
**often**
!
*
`clone`
a repository, do not download the
`.zip`
file.
*
Do
**not**
combine
`git`
commands
```
bash
$
git commit
-am
"myMessage"
# do not do this
```
*
Stage only 1 file at once using
```
bash
$
git add myFile.md
```
*
Commit
**only a few files**
at once (after multiple separate
`git add`
commands)
*
`Push`
often - avoid conflicts
Remember:
**A `push` a day keeps conflicts away!**
2019/2019-10-03_basicGitTraining-SIU/slides/branches.md
0 → 100644
View file @
0217f4da
# Development scheme
Generally, in a repository, there are guidelines for contributing.
<div
class=
"fragment"
>
A common development scheme is dual with a:
-
**development**
version of the code on
`develop`
-
**stable**
version of the code on
`master`
A
**version**
of the code is referred to as a
**branch**
.
<div
class=
"fragment"
>
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
<font
color=
"red"
>
In the practice repository, the development branch is called
`develop`
!
</font>
<div
class=
"fragment"
>

Use this dual development scheme for your own repositories!
# Branches
A
**version**
of the code (i.e., a
**branch**
) is made up of a sequence of code changes.
<div
class=
"fragment"
>
These individual code changes are called
**commits**
.
For instance, the
`master`
and
`develop`
branches can be represented as a timeline:
<img
src=
"slides/img/branch-master.png"
class=
"branch-master"
height=
"500em"
/>
# Switch between branches
List all branches of the repository with
```
bash
$
git branch
-a
```
Exit by typing
`q`
. The branch with the
*
is the current branch.
<div
class=
"fragment"
>
Checkout another branch
```
bash
$
git checkout <branchName>
```
<div
class=
"fragment"
>
You can switch to the
`develop`
branch with
```
bash
$
git checkout develop
```
If the local branch does not exist but the remote does, it is created automatically.
<div
class=
"fragment"
>
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
# Create your own version (i)
Assume that you want to work on a file:
<div
class=
"fragment"
>
<font
color=
"red"
>
Create a new
**branch**
!
</font>
```
bash
$
git checkout
-b
myBranch
```
The
`-b`
flag creates the branch. Locally, you have your own version now:
<img
src=
"slides/img/branch-create.png"
class=
"branch-create"
height=
"500em"
/>
# Create your own version (ii)
Push your version to your fork:
```
bash
$
git push origin myBranch
```
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
2019/2019-10-03_basicGitTraining-SIU/slides/essential_commands.md
0 → 100644
View file @
0217f4da
# The 5 essential commands
**Yes**
, you only need 5 commands!
`pull, status, add, commit, push`
or in other words (remember these!):
```
bash
$
git pull <remote> <branch>
$
git status
$
git add myFile.md
# example
$
git commit
-m
"myMessage"
# example
$
git push <remote> <branch>
```
# Pull the latest version of an existing branch
Pull the latest revision on branch
`myBranch`
:
```
bash
$
git pull origin myBranch
# Already up to date
```
<div
class=
"fragment"
>
Verify its
`status`
with:
```
bash
$
git status
```
# Modify a file
Copy the file
`firstNameLastname.md`
in the folder
`_attendees`
and rename it with your first and last names:
```
bash
$
cd
_attendees
$
cp
firstNameLastname.md myName.md
```
Then, make your changes with your favorite editor!
# Add your file to the stage
First, check the repository status
```
bash
$
git status
# uncommitted changes (displayed in red)
```
<div
class=
"fragment"
>
Now, add the file (bring it on stage)
```
bash
$
git add myName.md
# replace myName
$
git status
# returns the same as before, generally in green (means staged)
```
<div
class=
"fragment"
>
**ADVANCED**
: If there have been more changes after the file has been added, you can see your changes in the terminal
```
bash
$
git diff
```
exit with
`q`
# Add a commit message
```
bash
$
git commit
-m
"Add the profile of <myName>"
$
git status
```
# Push your file to your fork
```
bash
$
git push origin myBranch
```
<div
class=
"fragment"
>
**ADVANCED**
: see the log of all the commits (and your last one) in the terminal
```
bash
$
git log
```
exit by typing
`q`
.
\ No newline at end of file
2019/2019-10-03_basicGitTraining-SIU/slides/forks.md
0 → 100644
View file @
0217f4da
# What is a `fork`?
<center><img
src=
"slides/img/fork.jpg"
class=
"as-is"
height=
"500em"
/></center>
<!--http://www.cndajin.com/data/wls/246/22302193.jpg-->
# Not really ...
<center><img
src=
"slides/img/fork-crossed.png"
class=
"as-is"
height=
"500em"
/></center>
# What is a `fork`?
-
In general, when contributing to a repository, you only have
**read**
access.
-
In other words, you can only
**pull**
(unless it is your own repository or access has been granted).
-
In general, you
**cannot write**
changes. In other words, you do not have
**push**
access.
-
You have to work on your
**own copy**
.
-
In other words, you have to work on your own
<font
color=
"red"
>
**fork**
</font>
.
<h2>
How to get a fork?
</h1>
Browse to the original repository and click on the button
`Fork`
:

# Time to practice!
Fork the practice repository:
<br><br>
https://github.com/LCSB-BioCore/basic-git-practice
Then, clone your fork to your home directory!
```
bash
$
git clone git@github.com:<yourName>/basic-git-practice.git
```
Change to the practice directory with:
```
bash
$
cd
basic-git-practice
```
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
If you did not configure your SSH key, clone using HTTPS:
```
bash
$
git clone https://github.com/userName/basic-git-practice.git basic-git-practice
```
# A note on shortcuts ...
<font
color=
"red"
>
Any other rudimentary method such as
*'I simply download the `.zip` and unzip it - works like a charm!'*
shall
**be avoided**
!
</font>
**Why?**
# How to update my fork?
As you have your own fork, it will not automatically update once the original repository is update.

You have to update it yourself!
**More on that later!**
2019/2019-10-03_basicGitTraining-SIU/slides/github_gitlab.md
0 → 100644
View file @
0217f4da
# GitHub and GitLab
<img
src=
"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
alt=
"GitHub"
style=
"width: 200px;"
/>
<img
src=
"https://gitlab.com/gitlab-com/gitlab-artwork/raw/master/logo/logo-extra-whitespace.png"
alt=
"GitLab"
style=
"width: 200px;"
/>
GitHub and GitLab are VCS systems.
GitHub/Gitlab are both
**publicly available**
, but GitLab can be
**on-premise**
.
Positive point: GitHub and GitLab are (almost) the same.
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
-
**GitHub**
:
[
https://github.com
](
https://github.com
)
-
**GitLab**
:
[
https://gitlab.com
](
https://gitlab.com
)
\ No newline at end of file
2019/2019-10-03_basicGitTraining-SIU/slides/img
0 → 120000
View file @
0217f4da
../../2019-06-11_basicGitTraining/slides/img
\ No newline at end of file
2019/2019-10-03_basicGitTraining-SIU/slides/index.md
0 → 100644
View file @
0217f4da
# R3.school
## October 3rd, 2019
<div
style=
"top: 6em; left: 0%; position: absolute;"
>
<img
src=
"theme/img/lcsb_bg.png"
>
</div>
<div
style=
"top: 5em; left: 60%; position: absolute;"
>
<img
src=
"slides/img/r3-training-logo.png"
height=
"200px"
>
<br><br><br>
<h1>
Basic git training
</h1>
<br><br><br><br>
<h4>
Laurent Heirendt, Ph.D.
<br>
laurent.heirendt@uni.lu
<br>
<i>
Luxembourg Centre for Systems Biomedicine
</i>
</h4>
</div>
2019/2019-10-03_basicGitTraining-SIU/slides/list.json
0 → 100644
View file @
0217f4da
[
{
"filename"
:
"index.md"
},
{
"filename"
:
"overview.md"
},
{
"filename"
:
"what_is_git.md"
},
{
"filename"
:
"github_gitlab.md"
},
{
"filename"
:
"the_terminal.md"
},
{
"filename"
:
"forks.md"
},
{
"filename"
:
"branches.md"
},
{
"filename"
:
"essential_commands.md"
},
{
"filename"
:
"merge.md"
},
{
"filename"
:
"syncFork.md"
},
{
"filename"
:
"best_practices.md"
},
{
"filename"
:
"thanks.md"
}
]
2019/2019-10-03_basicGitTraining-SIU/slides/merge.md
0 → 100644
View file @
0217f4da
# Pull and merge requests
If you want your changes to be reflected on the
`develop`
or
`master`
branches,
**submit a PR**
via the Github interface.
Use the
**interface**
to make use of your peers to review your code!
<img
src=
"slides/img/branch-merge.png"
class=
"branch-merge"
height=
"500em"
/>
Once merged, you can delete the branch via the interface.
<div
class=
"fragment"
>
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
\ No newline at end of file
2019/2019-10-03_basicGitTraining-SIU/slides/overview.md
0 → 100644
View file @
0217f4da
# Overview
1.
What is
`git`
? What is the use of
`git`
?
2.
GitHub and GitLab
3.
The terminal
4.
What is a fork?
5.
What are branches?
6.
The 5 essential commands (
`pull`
/
`status`
/
`add`
/
`commit`
/
`push`
)
7.
What are merge/pull requests?
8.
How do I synchronize my fork?
9.
Best practices
2019/2019-10-03_basicGitTraining-SIU/slides/syncFork.md
0 → 100644
View file @
0217f4da
# Synchronize your fork (i)

Remember, we have to regularly update our own copy of the code.
Add the
`upstream`
address (original/protected repository)
```
bash
$
git remote add upstream git@github.com:LCSB-BioCore/basic-git-practice.git
```

Note the change in the URL.
You can then check whether the remote address is set correctly
```
bash
$
git remote
-v
```
<div
class=
"fragment"
>
Fetch the changes from upstream (similar to pull)
```
bash
$
git fetch upstream
```
# Synchronize your fork (ii)
Merge the retrieved changes on the
`master`
branch:
```
bash
$
git checkout master
$
git merge upstream/master
$
git push origin master
```
<div
class=
"fragment"
>
Do the same for the
`develop`
branch.
<img
src=
"slides/img/icon-live-demo.png"
height=
"100px"
>
\ No newline at end of file
2019/2019-10-03_basicGitTraining-SIU/slides/thanks.md
0 → 100644
View file @
0217f4da
# Let's refresh our memories
<div
class=
"fragment"
>
-
What is a
**fork**
?
<div
class=
"fragment"
>
-
What are
**branches**
?
<div
class=
"fragment"
>
-
Can I have
**multiple branches**
in my fork?
<div
class=
"fragment"
>
-
What is a good
**development scheme**
?
<div
class=
"fragment"
>
-
What are the
**5 essential commands**
?
# References & Cheat sheet
[
1
]:
Git
Book: https://git-scm.com/book/en/v2
[
2
]:
GitHub
training services: https://services.github.com/training/
[
3
]:
Cheat
sheet: http://rogerdudler.github.io/git-guide
# Thank you.
<img
src=
"slides/img/r3-training-logo.png"
height=
"200px"
>
Contact us if you need help:
r3lab.core@uni.lu
2019/2019-10-03_basicGitTraining-SIU/slides/the_terminal.md
0 → 100644
View file @
0217f4da
# Note on Microsoft Azure Devops
This course aims at the basics of using
`git`
.
In order to understand the concepts of
`git`
, the terminal will be used instead of any GUI.
The same terminology applies.
More info on Azure Devops & Git: https://docs.microsoft.com/en-us/azure/devops/repos/git/
# First steps in the terminal
Starting the terminal presents itself with a line where you can enter a command
```
bash
cesar@myComputer>
```
Often written, for covenience, as
```
bash
$
```
When you open your terminal (shell), you are located
in your home directory (unless otherwise configured), denoted as
`~/`
.
# Essential Linux commands (i)
List the contents of a directory
```
bash
$
ls
#-lash
```
Create a directory
```
bash
$
mkdir
myNewDirectory
```
Change the directory to a specific folder
```
bash
$
cd
myNewDirectory
```
Change the directory 1 level and 2 levels up
```
bash
$
cd
..
# 1 level up
$
cd
../..
# 2 levels up
```
# Essential Linux commands (ii)
Move a file or a directory
```
bash
$
mv
myFile.m myNewDirectory/.
```
Rename a file or a directory
```
bash
$
mv
myFile.m myNewFile.m
$
mv
myNewDirectory myDirectory
```
\ No newline at end of file
2019/2019-10-03_basicGitTraining-SIU/slides/what_is_git.md
0 → 100644
View file @
0217f4da
# What is `git`?
<!--  -->
`git`
is a
**version control system**
(VCS) for tracking changes in computer files and coordinating work on those files among multiple people [1].
Designed and implemented in 2005 by
**Linus Torvalds**
<div
align=
"center"
>
<img
src=
"slides/img/linus.jpg"
>
</div>
[1]
*https://en.wikipedia.org/wiki/Git*
# The inventor of `git`
<div
align=
"center"
>
<img
src=
"slides/img/git_definition.png"
>
</div>
`I'm an egotistical bastard, and I name all my projects after myself.
First Linux, now git.`
Linus Torvald (2007-06-14)
# What is the use of `git`?
*
No need to fully rewrite code;
**reuse code**
and
**save time**
*
Keep the changes you made over time (
**history**
)
*
Allows you to
**backtrack**
(if necessary) and undo unwanted changes
*
Easily
**add contributions**
of your collaborators to the main code base
note:
Other points to mention:
*
git shall not be considered as a nuisance, but as a tool that should help to track and trace the code.
*
git is not to track performance. Not using it shows exactly the opposite.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment