Slide 1

Slide 1 text

git git clone basics

Slide 2

Slide 2 text

version control what is this?

Slide 3

Slide 3 text

● records changes to a file (or set of files) ● allows to recall specific versions later ● allows to revert files back to a previous state ○ even the entire project can be reverted ● provides comparison between distinct states ● registers author or authors of the changes version control 3

Slide 4

Slide 4 text

● local ○ copy files into another directory ○ rcs — keeps patch sets in a special format on disk ● centralized ○ single server contains all versioned files — single point of failure ○ svn, perforce, cvs ● distributed ○ clients fully mirror entire repository ○ even when all servers fail, repository can be recovered from client’s copy ○ allows collaboration with different groups of people ○ git, mercurial, bazaar version control — types 4

Slide 5

Slide 5 text

about git a short history

Slide 6

Slide 6 text

● started in 2005, by Linux development community ○ In particular, Linus Torvalds, the creator of Linux ○ Linux kernel project began using a proprietary DVCS called BitKeeper ● developed with the following goals: ○ speed ○ simple design ○ strong support for non-linear development ○ fully distributed ○ able to handle large projects like the Linux kernel about git 6

Slide 7

Slide 7 text

git in a nutshell

Slide 8

Slide 8 text

● is like a mini filesystem or a stream of snapshots ○ everytime state is changed and saved, it takes a picture (snapshot) of current files ○ in new snapshots, it stores a link for previous files that have not changed git — what is 8

Slide 9

Slide 9 text

● almost all operations are performed locally ○ no additional information is needed from another computer ○ history is stored in the local “database” ○ it calculates locally the difference of multiple versions ○ every change in files is locally stored ● all changes are known ○ integrity is one of the most important characteristics ○ it is impossible to change a file without git knowing about it ● only adds data ○ it is very hard to erase data in any way git — what is 9

Slide 10

Slide 10 text

● commited ○ data is safely stored in local database ○ each commit is identified by a hash code (4c1f6...) ● modified ○ file has changed but those changes are not commited to database yet ● staged ○ marked one or more files to go into next commit git — three states of files 10

Slide 11

Slide 11 text

git — three sections of a project 11 Single checkout of one version of project. pulled from .git database and placed on disk to use or modify Information about what will go into the next commit a single file stores it Metadata and object database for project most important part of a git project

Slide 12

Slide 12 text

git — three sections of a project 12

Slide 13

Slide 13 text

git — lifecycle of the status of files 13 Tracked Any file that is not in last snapshot Files that are in last snapshot

Slide 14

Slide 14 text

git — lifecycle of the status of files 14 commited Tracked

Slide 15

Slide 15 text

git in practice

Slide 16

Slide 16 text

git-scm.com/downloads git — installation 16

Slide 17

Slide 17 text

● init — create an empty repository ■ $ git init ● clone — copy a remote repository to local disk ■ $ git clone ■ $ git clone git — create and clone 17

Slide 18

Slide 18 text

● determines which files are in which state ○ $ git status git — status 18

Slide 19

Slide 19 text

● start tracking new files ○ $ git add ○ $ git add ● stop tracking files ○ $ git rm ○ $ git rm ● unstage files ○ $ git reset HEAD ● discard changes in a given file ○ $ git checkout -- git — tracking and changing files 19

Slide 20

Slide 20 text

● save modified (that are staged) files ○ $ git commit -m git — commit 20

Slide 21

Slide 21 text

● displays the log of repository ○ $ git log ○ $ git log -p ■ shows differences in commits ○ $ git log --stat ■ shows log with statistics ○ $ git log --graph ■ shows log as a graph git — log 21

Slide 22

Slide 22 text

git branching in a nutshell

Slide 23

Slide 23 text

● is like a new pointer to the current commit ○ master is a branch that is tipically created by default git branch — what is 23

Slide 24

Slide 24 text

● is like a new pointer to the current commit ○ master is a branch that is tipically created by default ○ HEAD is a pointer (but not a branch) to current active branch git branch — what is 24

Slide 25

Slide 25 text

● is like a new pointer to the current commit ○ master is a branch that is tipically created by default ○ HEAD is a pointer (but not a branch) to current active branch ○ it allows to diverge paths of development git branch — what is 25

Slide 26

Slide 26 text

● it is possible to switch between branches ○ HEAD pointer is changed ○ $ git checkout testing git branch — switching 26

Slide 27

Slide 27 text

git branch — merging 27 ● two ways of merging ○ fast-forward ○ new commit (snapshot)

Slide 28

Slide 28 text

git branch — merging 28 ● two ways of merging ○ fast-forward ○ new commit (snapshot) go to master and merge hotfix

Slide 29

Slide 29 text

git branch — merging 29 ● two ways of merging ○ fast-forward ○ new commit (snapshot)

Slide 30

Slide 30 text

git branch — merging 30 ● two ways of merging ○ fast-forward ○ new commit (snapshot) go to master and merge iss53

Slide 31

Slide 31 text

git branch — merging 31 ● two ways of merging ○ fast-forward ○ new commit (snapshot)

Slide 32

Slide 32 text

git branch — merging 32 ● two ways of merging ○ fast-forward ○ new commit (snapshot) C5

Slide 33

Slide 33 text

git branch — merging conflicts 33 ● merges can have conflicts ○ they appear when the same part of files is changed in both branches
content
index.html
new content
index.html master testing

Slide 34

Slide 34 text

git branch — merging conflicts 34 ● git annotates conflicts ○ requires human intervention to resolve them ○ human chooses which one he wants and saves the file ○ human commits changes and tells git to continue
<<<<<<< HEAD:index.html content ============= new content >>>>>>> testing:index.html
index.html merge testing into master

Slide 35

Slide 35 text

git branch — merge flow 35 start merge contents merged conflicts? no manually resolve each conflict yes continue merge

Slide 36

Slide 36 text

git branching in practice

Slide 37

Slide 37 text

● create a new branch from current commit ○ $ git checkout -b ● delete a branch ○ $ git branch -D ● switch branches ○ $ git checkout git — branch 37

Slide 38

Slide 38 text

● merge a given branch into current one ○ $ git merge git — merge 38

Slide 39

Slide 39 text

git remote in practice

Slide 40

Slide 40 text

● manage remote repositories (remote servers) ○ $ git remote [-v] ■ lists configured remote servers ■ origin is the most common name of primary server ○ $ git remote add ■ adds a remote server to current local repository git — remotes 40

Slide 41

Slide 41 text

● push changes to remote server ○ $ git push ● fetch and merge changes from remote server to current version ○ $ git pull ● fetch changes ○ $ git fetch git — remote 41

Slide 42

Slide 42 text

● online book & try it ○ http://git-scm.com/book ○ https://try.github.io/levels/1/challenges/1 ● cheat-sheet ○ https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf ● git remote servers ○ https://github.com (public repositories) ○ https://gitlab.com (private repositories and teams) ○ https://bitbucket.com (private repositories) git — more info 42

Slide 43

Slide 43 text

questions?

Slide 44

Slide 44 text

Thank you Francisco Neves [email protected] GitHub, Twitter: @fntneves