# git basics
## for beginner-level git users
notes:
- close your laptops
- hand out cheat sheets later, no need to write stuff down
- if you have questions feel free to interrupt
## objectives
- teach you to fish
- hands-on experience
- use version control!
- collaborate!
## about version control
> records changes
what, who, when, why
## about git
### best tool for the job
- simple by design
- powerful if needed
- documentation
- industry standard
notes:
- git name: "the stupid content tracker"
- today we talk about the simple parts
- powerful parts in advanced course
- doc: also means community / stackoverflow entries
## about today
be able to ...
1. use git in **ALL** your projects
2. collaborate with each other
... is mission accomplished.
notes:
- there is time for fancy stuff later
- take a few weeks getting used to git
- delay is good to grow your own experience
- growing pain is how we learn
## about christian
- scientific computing support @ iDiv since 2014
- happy git user since 2010
> There will never be a better version control system than git.
>
> -- Christian Krause, 2017
## about dirk
- statistics and R support @ iDiv since 2014
- knows that kind of pain:

## about you

name, job, git experience, why git?
notes:
- re-seat everyone so that experienced user sits together with
inexperienced user
# motivation
> Why should I use git?
## motivation #1
### avoid mess

notes:
- who has seen such a mess?
- who has contributed to such a mess?
- who has created such a mess?
## motivation #1
### want structure

notes:
- TODO better repo with more contributors
- structure
- who, when, why
## motivation #2
### throw-away playgrounds

notes:
- test stuff without interfering
- throw away if garbage
- integrate if good
- switch back and forth
- (done right) decision based on regression testing
## motivation #3

notes:
- there's a rule in ~~open source software~~ nay life
- if you want the world to be a better place
- complain about it (issue tracker)
- if you are able to fix it: do it!
## motivation #3
### collaboration made easy
> This text cuntains a typo.
notes:
- demo GitLab
- [go to project](https://git.idiv.de/sc/edu/git-seminar)
- check if typo still in master
- edit
- change **target branch** to create merge request
- commit message:
```
fixes typo
learn how to use a spell checker, dude!
```
## motivation #4
### the creative use of git award
#### goes to Michael Schilli
```yml
videos:
- id: '_3i5yVoTvCs'
title: 'How to flip German pancakes'
- id: 'brPfE66FC24'
title: 'Tivo Stream Cooling Fan Replacement'
```
```console
$ youtube-sync -i videos.yml
_3i5yVoTvCs: Unchanged
brPfE66FC24: Updated OK
```
source: [Linux Magazin](http://www.linux-magazin.de/) 2018/01
## motivation #e
### use version control for
# *everything*
| common | less frequent | esoteric? |
| ------------ |:---------------:| ---------------:|
| software | presentation | youtube |
| blog / doc | paper / thesis | soundboard |
| user config | task management | drinking games |
notes:
- software, thats obvious
- blog / doc: web-pages in general are more and more managed by git
- e.g. this git cheat sheet we're handing out is a git repo
- if it doesn't support git don't use it
## motivation #a
### automation
- software testing
- code quality
- build app and deploy to app store
- put presentation on web server
*(see advanced seminar)*
notes:
- basically, everything you can script
# setup
notes:
- installation
- configuration
## command line
- Ellen Ripley uses command line
- Chuck Norris uses command line
## os packages
- **Linux:** bash and git
- **Mac:** bash and git
- **Windows 10+:** WSL
- **Windows < 10:** cmder
notes:
- WSL = [Windows Subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
## command line
### description syntax
```bash
# command
git
# sub-command
git status
# argument
git diff README.md
# optional argument
git diff [--staged]
```
## command line
### git syntax
```bash
# every git command
git command [arguments]
# get help
git help [command]
```
## git setup
```bash
# configure your identity
git config --global user.name 'Jane Doe'
git config --global user.email 'jane.doe@riot-grrrl.org'
# show colors
git config --global color.ui auto
# editor
git config --global core.editor emacs
# configure aliases
git config --global alias.unstage 'reset HEAD --'
git config --global alias.lol \
'log --graph --decorate --oneline --all'
```
# git command line
## local repositories
## command line
### create repositories
```bash
# create empty repository
git init project-name
# create repository from existing project
# which is not under version control
cd path/to/project
git init
```
## command line
### git status
```bash
# show status and what to do
git status
```
notes:
- important git command
- shows a lot of information
- shows basic git commands
- later, we'll see different outputs
## internals
### the staging area

## command line
### file handling
```bash
# use staging area
git stage file
git unstage file
# discard changes
git checkout file
# rename and remove
git mv source destination
git rm file
```
## command line
### show changes
```bash
# from staging area to current working copy
git diff
# show contents of staging area, i.e.
# from last commit to staging area
git diff --staged
```
## command line
### commit changes
```bash
# opens editor for you to edit commit message
git commit
# commits with a short message
git commit -m 'adds license and readme'
```
## command line
### view history
```bash
# show all commits
git log
# show all commits plus diff
git log --patch
# shows condensed view of history, i.e.
# - only commit message subjects
# - one per line
git lol
```
## demo
### basic commands
notes:
- mkdir ~/projects
- git init hello
- README.md
- LICENSE
- src/hello.py
## software licenses

https://choosealicense.com
## no license
- exclusive copyright to **each!** author
- **no one** can use, copy, distribute and modify
- platform: terms of service
https://choosealicense.com
## other licenses
- media, documentation: creative commons
- paper / thesis: journal vs legal department
https://choosealicense.com
# [cheat sheet](https://idiv-biodiversity.github.io/git-cheat-sheet/)
# your turn
- pick project
- make commits
- use status and diff!
notes:
- deputize those who already have
# distributed
## version control system
## git usage until now
- has all been local
- repo contains entire project history
- not yet answered:
- how to publish?
- how to contribute?
## remotes

### how do i get remotes?
# web apps
- GitLab demo
- GitHub (no demo)
## command line
### clone repositories
```bash
# create local copy of existing repository
git clone https://github.com/user/project-name.git
```
## your turn
- log in
- create project
- fetch / push / pull
## command line
### git
```bash
```
## command line
### git
```bash
```
## homework #1
### use git
for each project you use ...
... create repository in GitLab ...
... and commit changes!
## homework #2
### collaborate
- talk with your colleagues
- organize project(s) you use together
- open issues for problems and features
- contribute via merge requests
- review commits and merge requests
## homework #3
be friendly
be responsible
be open
be creative
be proactive
have fun