Slide 1

Slide 1 text

Git started Introduction to distributed version control with Git Yannick Baron @yannick_baron [email protected]

Slide 2

Slide 2 text

“Git is easy”

Slide 3

Slide 3 text

Clone the repository “Git is easy”

Slide 4

Slide 4 text

Clone the repository Make changes “Git is easy”

Slide 5

Slide 5 text

Clone the repository Make changes Mess things up “Git is easy”

Slide 6

Slide 6 text

Clone the repository Make changes Mess things up Look at StackOverflow “Git is easy”

Slide 7

Slide 7 text

Clone the repository Make changes Mess things up Look at StackOverflow Mess things up even more “Git is easy”

Slide 8

Slide 8 text

Clone the repository Make changes Mess things up Look at StackOverflow Mess things up even more Delete folder “Git is easy”

Slide 9

Slide 9 text

Clone the repository Make changes Mess things up Look at StackOverflow Mess things up even more Delete folder Clone the repository “Git is easy”

Slide 10

Slide 10 text

Clone the repository Make changes Mess things up Look at StackOverflow Mess things up even more Delete folder Clone the repository … “Git is easy”

Slide 11

Slide 11 text

https://stackoverflow.com/questions?tab=Votes

Slide 12

Slide 12 text

https://stackoverflow.com/questions?tab=Votes

Slide 13

Slide 13 text

Using git for 12 years now Noticed very different levels of experience Concepts often misunderstood despite daily use I <3 git

Slide 14

Slide 14 text

Time travel: Go back in time History of how project evolved Compare versions to find errors Build releases on versions Work on the same files in parallel Why version control?

Slide 15

Slide 15 text

Time travel: Go back in time History of how project evolved Compare versions to find errors Build releases on versions Work on the same files in parallel Why version control?

Slide 16

Slide 16 text

Save our butts Make us feel safe when confidently editing code Why version control for real?

Slide 17

Slide 17 text

Comfortable with Git?

Slide 18

Slide 18 text

Comfortable with Git?

Slide 19

Slide 19 text

Changes are kept track of locally Most operations performed locally Server mostly for storage only Control of when to communicate with a remote machine = fast + independent of connection Distributed?

Slide 20

Slide 20 text

Story: Writing a “book” with git Live Demo

Slide 21

Slide 21 text

Intro + chapter files Script to bundle them to a book Demo Project

Slide 22

Slide 22 text

git init initializes a git repository git status information about the current state git add adds current version of a file git commit –m “” saves added files to the history Gitting started is easy

Slide 23

Slide 23 text

The git history is a graph, a tree to be precise A node in that tree is the state of our files at a point in time Most operations deal with how to navigate and manipulate that tree The git history

Slide 24

Slide 24 text

A hierachical graph data structure Consists of nodes and edges Various ways of implementation fixed number of child nodes list of child nodes reference to parent node … Quick Interlude: Trees

Slide 25

Slide 25 text

Reference to parent node Node { parent?: Node; data: any; } const A = new Node(); Quick Interlude: Trees A

Slide 26

Slide 26 text

Reference to parent node Node { parent?: Node; data: any; } const t = new Node(); t.parent = A; A = t; Quick Interlude: Trees A

Slide 27

Slide 27 text

Reference to parent node Node { parent?: Node; data: any; } const B = A; Quick Interlude: Trees A B

Slide 28

Slide 28 text

Reference to parent node Node { parent?: Node; data: any; } const t = new Node(); t.parent = B; B = t; Quick Interlude: Trees B A

Slide 29

Slide 29 text

Reference to parent node Node { parent?: Node; data: any; } Quick Interlude: Trees B A

Slide 30

Slide 30 text

Reference to parent node Node { parent?: Node; data: any; } B = undefined; Quick Interlude: Trees A

Slide 31

Slide 31 text

The git history is a graph, a tree to be precise A node in that tree is the state of our files at a point in time Most operations deal with how to navigate and manipulate that tree The git history

Slide 32

Slide 32 text

git add --all adds all untracked files at once git status information about the current state git commit –m “” saves added files to the history Growing the tree

Slide 33

Slide 33 text

git branch creates a new branch at HEAD git checkout moves HEAD to branch git commit –am “” -a add all tracked files & commits Adding a branch

Slide 34

Slide 34 text

git checkout moves HEAD to branch git diff show the diff of current changes --word-diff do a word diff git commit –am “” -a add all tracked files & commits Switching branches

Slide 35

Slide 35 text

git diff diff between HEAD and given branch git checkout moves HEAD to branch git merge –m “” merges branch into current branch git branch –d deletes given branch Reintegrating a branch

Slide 36

Slide 36 text

git init git status git add git commit git branch git checkout git diff git merge Recap #1

Slide 37

Slide 37 text

git log shows full detail log of all commits git log --oneline shows list of commit messages git log --graph --oneline shows graph of commit messages The Log and Hashes

Slide 38

Slide 38 text

https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs/35075021#35075021

Slide 39

Slide 39 text

git checkout -- checks out file in given version git diff --staged shows a diff of the staged files git reset --hard move current branch back to SHA --hard discard all changes --soft keep changes We have to go back!

Slide 40

Slide 40 text

git remote add adds a remote repository git push -u push branch and setup tracking Going online for the first time

Slide 41

Slide 41 text

Starting from existing Repo git clone [] makes working copy of repo at url git log --graph --oneline shows graph of commit messages Multiplayer

Slide 42

Slide 42 text

git checkout –b -b create and switch to branch git commit –am “” -a add all tracked files & commits git push push changes of current branch Player 2 has entered the game

Slide 43

Slide 43 text

git fetch download changes from the remote git checkout moves HEAD to branch git pull fetches and merges tracked branch into current branch git rebase replay branch’s commits on top of base Receiving changes

Slide 44

Slide 44 text

git merge –m “” merges branch into current branch git commit –am “” -a add all tracked files & commits git push : deletes branch on remote git branch –d deletes given branch Dealing with conflicts

Slide 45

Slide 45 text

git log git reset git clone git remote git push git fetch git pull git rebase Recap #2

Slide 46

Slide 46 text

We have seen 16 basic commands That’s all you need to git started Just the tip of the iceberg Git is a skill, a tool in your tool belt Expertise makes your life easier Low cost, high reward Try it! Git going!

Slide 47

Slide 47 text

and their features GitHub https://github.com BitBucket https://bitbucket.org GitLab https://gitlab.com Create online repositories Fork Repositories Pull Requests Tools for Code Reviews Continuous Integration Build Pipelines Web platforms

Slide 48

Slide 48 text

GitHub interactive Introduction https://try.github.io/ Think like a git http://think-like-a-git.net/ Watch this talk again https://youtu.be/S_OkNMHinlg GitHub Git Cheatsheet https://services.github.com/on- demand/downloads/github-git- cheat-sheet.pdf Resources

Slide 49

Slide 49 text

Thank you! Questions? Contact @yannick_baron [email protected]

Slide 50

Slide 50 text

git reset # to unstage git commit --amend git pull --rebase (demo) conflict when rebasing git revert git add -p git rebase –i git stash git bisect uncommit Bonus Round