+ - 0:00:00
Notes for current slide
Notes for next slide

Let’s git together

Frie Preu

codecentric AG

2019-09-06

1 / 71

alternative title: Let's git our sh*t together!

2 / 71

Who am I?

  • Frie Preu
  • data scientist / IT consultant / software developer at codecentric
  • volunteer at CorrelAid: IT infrastructure, internal projects (R packages), miscellaneous mischief
  • Add me:
3 / 71

Slides, installation and account creation

4 / 71

Partner up!

Mona Lovalace Octocat

Mona

-> Ada Lovelace

Grace Hopper Octocat

Grace

-> Grace Hopper

5 / 71

Why Git?

  • masterthesis.docx
6 / 71

Why Git?

  • masterthesis.docx
  • masterthesis_v1.docx
6 / 71

Why Git?

  • masterthesis.docx
  • masterthesis_v1.docx
  • masterthesis_FINAL.docx
6 / 71

Why Git?

  • masterthesis.docx
  • masterthesis_v1.docx
  • masterthesis_FINAL.docx
  • masterthesis_FINAL_TimsEdits.docx
6 / 71

Why Git?

  • masterthesis.docx
  • masterthesis_v1.docx
  • masterthesis_FINAL.docx
  • masterthesis_FINAL_TimsEdits.docx
  • masterthesis_FINAL_FINAL.docx
6 / 71

Help

7 / 71

Version Control to the Rescue!

8 / 71

Download data - fork and clone

9 / 71

Fork and clone

Repository

A Git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed. (Source)

10 / 71

Fork and Clone

Fork

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. (Source)

Clone

Cloning a repository syncs it to your local machine. After you clone, you can add and edit files and then push and pull updates. (Source)

11 / 71

Hands On 1 - fork a repo

Mona

  1. https://github.com/friep/git-our-shit-together-test-repo/: Fork (top right)
  2. https://github.com/{USERNAME}/git-our-shit-together-test-repo opens
  3. go to Settings->Collaborators and add Grace as a collaborator
12 / 71

Detour: SSH vs HTTPS

13 / 71

SSH vs HTTPS

Git clone

-> influences how GitHub authenticates you

14 / 71

Authentification

HTTPS

  • with GitHub username + password
  • Gitkraken: just magically works 🎉
  • Command line: possibly need to enter username + password

SSH

  • with a keypair (id_rsa.pub and id_rsa)
  • public key, private key cryptography (siehe z.B. Youtube)
  • advantage: only set up once, no need to remember password
  • clone ssh://...
15 / 71

Hands On 1.1: connect Gitkraken with GitHub

  1. Gitkraken profile (top right)
  2. Preferences->Authentification->GitHub
  3. connect to GitHub
  4. Generate SSH key and add to GitHub
16 / 71

Hands On 2 - clone a repo

Mona & Grace

Git clone

  1. Gitkraken: Clone Repo -> Clone with URL
  2. enter copied link to URL field
17 / 71

Real life

  • open source contribution: fork + clone
  • job / collab with friends: only clone
18 / 71

Save your files - Add und Commit

19 / 71

Commit

Commit

A commit is the Git equivalent of a "save".[...] Git committing is an operation that acts upon a collection of files and directories. (Source)

--> Commit = a "save point" in Git.

20 / 71

Commit

  • a commit saves changes w.r.t. the previous commit
    • edits of file(s)
    • creation of new file(s)
    • deletion of file(s)
    • renaming of file(s)
  • a commit can contain several changes!
21 / 71

Adding and Staging Area

Staging Area

(Source: https://git-scm.com/about/staging-area)

22 / 71

Commit history

Git commits

23 / 71

Go back in time!

Time Machine

24 / 71

Hands On 3 - Go back in time

  1. reset master to this commit
  2. play with: hard, mixed, soft
  3. fast forward master to origin/master (commit at top)
25 / 71

Detour: RMarkdown and xaringan

26 / 71

RMarkdown

27 / 71

xaringan

  • package to make RMarkdown presentations
  • install.packages("xaringan")
  • xaringan::inf_mr() with index.Rmd open
28 / 71

Hands On 4 - make a commit

Grace + Mona

  1. Change stuff (e.g. README.md or index.Rmd)
  2. GIT ADD the "unstaged files" you want to commit / "save in Git"
  3. write a (at least partly) informative "commit message"
  4. GIT COMMIT
29 / 71

Git quizzed!

Lokal

30 / 71

Git quizzed!

Lokal

31 / 71

Sync files - Push and Pull

32 / 71

Git Hosting

  • GitHub:
  • GitLab:
  • Keybase:
33 / 71

Git local and git remote

... what?

  • local: your laptop / machine
  • remote: in the Cloud (GitHub, GitLab, ...)

Gitkraken Lokal Remote

34 / 71

Sync: Git Pull and Git Push

  • Git Pull: "download" new commits from GitHub / GitLab
  • Git Push: "upload" the commits you made locally to GitHub / GitLab
35 / 71

Sync: Git Pull and Git Push

Push Pull

36 / 71

Push the button

37 / 71

Hands On 5 - Pull and Push

  1. Grace: Push
  2. Mona: Pull
  3. Mona: Push
  4. Grace: Pull
38 / 71

Git quizzed!

Push Pull

39 / 71

Git quizzed!

Push Pull

40 / 71

When things go wrong...

41 / 71

git google

42 / 71

xccd

43 / 71

When things go wrong...

  1. as long nothing is pushed, all is (kind of) ok -> don't push if things are messed up!
  2. if things are really messed up: save your code somewhere else and clone again
44 / 71

Merge conflicts

Merge conflicts occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file. (Source)

45 / 71

Merge conflicts

  1. you commit changes
46 / 71

Merge conflicts

  1. you commit changes
  2. you pull to get the newest updates
46 / 71

Merge conflicts

  1. you commit changes
  2. you pull to get the newest updates
  3. your coworker has changed something that clashes with your changes
46 / 71

Merge conflicts

  1. you commit changes
  2. you pull to get the newest updates
  3. your coworker has changed something that clashes with your changes
  4. git:
46 / 71

up to you

47 / 71

Solving merge conflicts

  • you need to solve merge conflicts on your machine -> decide which version / changes you keep
  • Gitkraken has an integrated merge conflict tool
48 / 71

Hands on 6: Merge conflicts

  1. Mona or Grace: edit README.md on GitHub in a certain line
  2. Mona & Grace: edit README.md locally on your machine in the same line (edit it differently!)
  3. Monat & Grace: commit your own changes (don't push yet!)
  4. Mona & Grace: pull
  5. Mona & Grace: solve the merge conflict locally and push your own version.
49 / 71

Sidenote: Git stash

-> something Gitkraken often does for you to keep your changes safe.

git stash temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on. Stashing is handy if you need to quickly switch context and work on something else, but you're mid-way through a code change and aren't quite ready to commit. (Source)

50 / 71

Sidnote: Git stash

stash

--> put it away for now!

51 / 71

Git stash for solving merge conflicts

  1. git stash
  2. git pull
  3. apply stash
  4. solve merge conflicts
  5. (delete stash)
52 / 71

work with GitHub

53 / 71

Issues

54 / 71

Issues

55 / 71

Hands On 7: Issues

  1. Mona: create an issue "add Grace's favorite GIF"
  2. Grace: go to giphy.com, find a funny gif and add it to the presentation (-> copy link)
  3. Grace: add + commit. link the issue number in the commit message (#issueno)
  4. Grace: push
  5. Mona: reload the issue (ctrl + r)
56 / 71

Recap issues

  • very useful for project organization
  • discussion is centralized (but: don't put sensitive information in GitHub)
  • Tip: create a GitHub project with a kanban board for process tracking
57 / 71

Branches and Pull Requests

58 / 71

Gitkraken branching

59 / 71

Come on

60 / 71

Branches

Branch

A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit process. You can think of them as a way to request a brand new working directory, staging area, and project history. (Source)

Checkout

The git checkout command lets you navigate between the branches created by git branch. Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. Think of it as a way to select which line of development you’re working on. (Source)

61 / 71

Why branches?

  • stability: only have working code on "master" branch
    • e.g. CI/CD directly to dev
    • users download your code from GitHub (e.g. devtools::install_github())
62 / 71

Why branches?

  • stability: only have working code on "master" branch
    • e.g. CI/CD directly to dev
    • users download your code from GitHub (e.g. devtools::install_github())
  • collaboration: independent development of code ("feature branches")
62 / 71

Why branches?

  • stability: only have working code on "master" branch
    • e.g. CI/CD directly to dev
    • users download your code from GitHub (e.g. devtools::install_github())
  • collaboration: independent development of code ("feature branches")
  • experiments: try it out in a branch
62 / 71

Why branches?

  • stability: only have working code on "master" branch
    • e.g. CI/CD directly to dev
    • users download your code from GitHub (e.g. devtools::install_github())
  • collaboration: independent development of code ("feature branches")
  • experiments: try it out in a branch
  • example: https://github.com/jandix/sealr/branches
62 / 71

Branches Workflow

  1. create a branch in Gitkraken with a meaningful name (e.g. issue1-add-favorite-gif)
63 / 71

Branches Workflow

  1. create a branch in Gitkraken with a meaningful name (e.g. issue1-add-favorite-gif)
  2. checkout branch (double-click on branch name in Gitkraken)
63 / 71

Branches Workflow

  1. create a branch in Gitkraken with a meaningful name (e.g. issue1-add-favorite-gif)
  2. checkout branch (double-click on branch name in Gitkraken)
  3. continue working as usual (pull-commit-push cycles)
63 / 71

Branches Workflow

  1. create a branch in Gitkraken with a meaningful name (e.g. issue1-add-favorite-gif)
  2. checkout branch (double-click on branch name in Gitkraken)
  3. continue working as usual (pull-commit-push cycles)
  4. (optional: merge other branches into your branch to get their updates)
63 / 71

Branches Workflow

  1. create a branch in Gitkraken with a meaningful name (e.g. issue1-add-favorite-gif)
  2. checkout branch (double-click on branch name in Gitkraken)
  3. continue working as usual (pull-commit-push cycles)
  4. (optional: merge other branches into your branch to get their updates)
  5. merge your branch into the master branch
63 / 71

Merging branches

  • Gitkraken: right-click on branch name or master
  • depends on which branch is ahead of which and which branch is currently checked out (?)
  • right-click on master: merge master into issue1-add-favorite-gif -> branch is updated
  • right-click on branch: merge issue1-add-favorite-gif into master -> master is updated (usually via Pull Request)
64 / 71

Pull Requests (PRs)

Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch. (Source)

  • to be used in combination with branches
  • useful "review" and feedback functionality
65 / 71

Hands on 8 - branches & pull requests

  1. Grace & Mona together: create a new issue (think of something!)
  2. Mona: create a branch called issue2-{description} locally
  3. Mona & Grace: work together on issue 2 on Mona's machine
  4. Mona: push the branch
  5. Mona: open a pull request and assign Grace as a reviewer
  6. Grace: review Mona's PR and merge it
66 / 71

Real life: Branches and Pull Requests

  • branches
    • very useful when developing R packages / applications / shiny apps in a team: feature branches
    • relevance for data analysis projects: enables working in parallel on several methods, keep master clean of non-working code, backup (!)
  • pull requests
    • centralize discussion
    • code review stage
67 / 71

Recap

68 / 71

What we learned today

  • Fork and clone a GitHub repository
69 / 71

What we learned today

  • Fork and clone a GitHub repository
  • make a commit in Gitkraken
69 / 71

What we learned today

  • Fork and clone a GitHub repository
  • make a commit in Gitkraken
  • pull and push commits from / to GitHub
69 / 71

What we learned today

  • Fork and clone a GitHub repository
  • make a commit in Gitkraken
  • pull and push commits from / to GitHub
  • work with branches and pull requests
69 / 71

That's it!

70 / 71

If you ever need help...contact me!

Frie Preu

71 / 71

alternative title: Let's git our sh*t together!

2 / 71
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow