47
GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY 1

GETTING TO KNOW GIT: PART II - Xojocdn.xojo.com/WebinarExamples/Xojo Webinar - Getting To Know Git... · • GitFlow is a popular branching model

Embed Size (px)

Citation preview

G E T T I N G T O K N O W G I T:

PA R T I I

J U S T I N E L L I O T T P E N N S TA T E U N I V E R S I T Y

1

R E V E R T I N G C H A N G E S

2

R E V E R T I N G C H A N G E S

• Change local files

• git reset

• git checkout

• Revert a commit in the branch history

• git revert

• Reset a file demo in SourceTree…

3

S TA S H ’ I N G C H A N G E S

4

S TA S H T E M P C H A N G E S

• Saves changes to temporary area locally

• Does not create a commit to the repository

• Useful for switching to other branches without losing your work

• Restore the stash when ready to re-apply modifications

• Stash Demo in SourceTree…

5

TA G S

6

TA G S

• Bookmarks a specific commit

• Useful for major version numbers

• Naming Conventions

• Label with version, Xojo Version, Plugin Versions, OS Version

• No white space permitted

• Converted from SVN will have ‘%20’

• Tag demo in SourceTree…

7

B R A N C H E S

8

B R A N C H E S

• Branches are a separate line of development

• A branch represents the tip of a series of commits

• Branches are just pointers to commits

• It's not a container for those commits

9

B R A N C H E S

• “master” is the default branch

• Help to separate lines of development

• Merging of branches is where Git excels

• GitFlow is a popular branching model

• Ex: Master, HotFix, Develop, Feature, Release

10

B R A N C H E S

• $ git checkout master

• Create and switch to new branch

• $ git checkout -b <branch>

• Delete branch

• $ git branch -d <branch>

11

B R A N C H W A L K T H R O U G H

M 1

First Commit

12

B R A N C H W A L K T H R O U G H

M 1

New Branch

B 1

13

B R A N C H W A L K T H R O U G H

M 1

B 1 B 2

Second Branch Commit

14

B R A N C H W A L K T H R O U G H

M 1

B 1 B 2 B 3

Third Branch Commit

15

B R A N C H W A L K T H R O U G H

M 1

B 1 B 2 B 3 B 4

Fourth Branch Commit

16

B R A N C H W A L K T H R O U G H

M 1

Merge Branch To Master

B 1 B 2 B 3 B 4

M 2

(Branch Deleted

After Merge)

17

D E TA C H E D H E A D R E F E R E N C E

• HEAD is a reference to latest commit in branch OR a specific commit

• Internally, the git checkout command simply updates the HEAD to point to either the specified branch or commit.

• The point is, your development should always take place on a branch—never on a detached HEAD. This makes sure you always have a reference to your new commits.

• What does "detached HEAD" mean, and why should I care?

• Occurs when you check out a specific commit in a branch versus the latest commit of branch

18

G I T F L O W B R A N C H I N G M O D E L

19

G I T F L O W

• “A successful Git branching model”

• Only branch from and merge to the Master branch

• Master, HotFix, Release, Development, Features

• http://nvie.com/posts/a-successful-git-branching-model/

20

G I T F L O W : H O T F I X B R A N C H

C 1

First Commit

21

G I T F L O W : H O T F I X B R A N C H

C 1 C 2

Second Commit

22

G I T F L O W : H O T F I X B R A N C H

C 1 C 2 C 3

Third Commit

23

G I T F L O W : H O T F I X B R A N C H

C 1 C 2 C 3

H F 1

HotFix Branch Commit

24

G I T F L O W : H O T F I X B R A N C H

C 0 C 1 C 2

H F 1

C 3

Third (Merge) Commit

25

G I T F L O W : H O T F I X B R A N C H

C 0 C 1 C 2

H F 1

C 3 C 4

Fourth Commit

26

R E M O T E S

27

R E M O T E R E P O S

• Local repo on your client only

• Remote is a Git host to push to

• You clone, push, fetch and pull from remotes

28

S TA N D A R D G I T W O R K F L O W

Working Directory

Staging Area

Repository

Remote

29

R E M O T E R E P O S

• Network Protocols

• SSH

• HTTPS

• Git Protocol (daemon)

30

S E L F - H O S T E D R E P O S

• SSH

• Enable SSH, create “bare” repository on server

• Atlassian Stash

• Enterprise GitHub

• GitLab

31

R E M O T E R E P O S

• 3rd Party

• GitHub, BitBucket, Google Code

• CodeSpaces, SourceRepo

• Assembla, Gitorious

• And possibly more, I’m betting …!

32

C L O N I N G A R E P O S I T O R Y

• The process of copying an existing Git repository to your computer

• A cloned repo includes the entire file history changes and commit messages

• Git clone command example:

• $ git clone https://server.edu/RepoName.git

33

P U S H I N G C H A N G E S

• $ git push origin master

• Push (upload) the ‘master’ branch to the ‘origin’ remote host

• First remote is named origin

• Recommended not to rename this (GUI Apps assume naming convention)

34

G I T 2 . 0 P U S H D E FA U LT S

• Starting with Git version 2.0 push will default to ‘simple’ - push only the active branch you are on

• Previous behavior was to push all matching branches

• Could be dangerous, might miss that some branches updated without you remembering it

• $ git config --global push.default simple

35

F E T C H I N G

• Fetching updates your local Git repo of the remote’s status of commits, branches, tags

• Fetching from remote repo host does not change your local files

• Use when you want to update what your local Git repo knows about the remote’s commits, branches, tags

36

R E M O T E S D E M O

• Create remote repo

• Add remote to local repo settings

• Local branches tracks remote branches

• Push full local repo to remote

• Commit locally, then push to origin remote

• Local branches and stashes never pushed to remote

37

D E B U G G I N G T O O L S

38

D E B U G G I N G W I T H G I T

• File Annotation with “git blame”

• Use when you know where a bug is

• Binary Search with “git bisect”

• Very helpful when you can’t determine which commit the bug was introduced

39

B I S E C T - B I N A R Y S E A R C H

• Bisect demo at the command line…

40

L E S S O N S L E A R N E D

41

L E S S O N S L E A R N E D

• Learn the basics of the command line

• Helpful for when odd errors occur

• Access features not always available in GUI Apps

42

L E S S O N S L E A R N E D

• Embrace Branches

• Init project for GitFlow

• Use the ‘Develop’ and ‘HotFix’ branches to start

• Very easy to do in SourceTree

43

F O R M O R E I N F O …

44

R E S O U R C E S A N D T R A I N I N G

• Official Git Site

• http://git-scm.com

• Git Cheat Sheets

• Git Pro Book

45

R E S O U R C E S A N D T R A I N I N G

• http://try.github.com

• http://atlassian.com/git

• O’Reilly

• “McCullough and Berglund on Mastering Git”

46

Justin Elliott jelliott [at] psu.edu

!@justindelliott

T H A N K Y O U .

47