learning git with workflows

171
Learning Git with Workflows Mosky

Upload: mosky-liu

Post on 07-May-2015

1.037 views

Category:

Technology


6 download

DESCRIPTION

It is the slides for SITCON[1] 2013 Workshop[2]: "Git - The Version Control System You Must Know". [1]: http://sitcon.org/ [2]: http://www.openfoundry.org/tw/activities/details/415-the-open-source-way-coder

TRANSCRIPT

Page 1: Learning Git with Workflows

Learning Git with Workflows

Mosky

Page 2: Learning Git with Workflows

This slides

2

Page 3: Learning Git with Workflows

This slides

won't

explain every options of Git commands;

and the internal of Git.

2

Page 4: Learning Git with Workflows

This slides

won't

explain every options of Git commands;

and the internal of Git.

will

let you start to use Git immediately;

and learn the common Git workflows.

2

Page 5: Learning Git with Workflows

Mosky

3

Page 6: Learning Git with Workflows

Mosky

A Python engineer at Pinkoi

3

Page 7: Learning Git with Workflows

Mosky

A Python engineer at Pinkoi

An author of some Python packages

MoSQL, Clime, ...

3

Page 8: Learning Git with Workflows

Mosky

A Python engineer at Pinkoi

An author of some Python packages

MoSQL, Clime, ...

A speaker at several conferences

PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ...

3

Page 9: Learning Git with Workflows

Mosky

A Python engineer at Pinkoi

An author of some Python packages

MoSQL, Clime, ...

A speaker at several conferences

PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ...

A Python trainer

3

Page 10: Learning Git with Workflows

Mosky

A Python engineer at Pinkoi

An author of some Python packages

MoSQL, Clime, ...

A speaker at several conferences

PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ...

A Python trainer

http://mosky.tw/

3

Page 11: Learning Git with Workflows
Page 12: Learning Git with Workflows
Page 13: Learning Git with Workflows
Page 14: Learning Git with Workflows

Outline

6

Page 15: Learning Git with Workflows

Outline

Setup Git

6

Page 16: Learning Git with Workflows

Outline

Setup Git

Routine

Core

Secondary

6

Page 17: Learning Git with Workflows

Outline

Setup Git

Routine

Core

Secondary

Branching

6

Page 18: Learning Git with Workflows

Outline

Setup Git

Routine

Core

Secondary

Branching

Remote Repository

6

Page 19: Learning Git with Workflows

Outline

Setup Git

Routine

Core

Secondary

Branching

Remote Repository

A Co-working Workflow

6

Page 20: Learning Git with Workflows

Setup Git

Page 21: Learning Git with Workflows

Get Git!

8

Page 22: Learning Git with Workflows

Get Git!

Ubuntu, Debian or any APT-based Linux

$ sudo apt-get install git-core

8

Page 23: Learning Git with Workflows

Get Git!

Ubuntu, Debian or any APT-based Linux

$ sudo apt-get install git-coreMac

$ brew install githttp://brew.sh/

8

Page 24: Learning Git with Workflows

Get Git!

Ubuntu, Debian or any APT-based Linux

$ sudo apt-get install git-coreMac

$ brew install githttp://brew.sh/

Windows

http://git-scm.com/download/win

8

Page 25: Learning Git with Workflows

Is Git there?

9

Page 26: Learning Git with Workflows

GUIs are available

10

Page 27: Learning Git with Workflows

GUIs are available

Thanks GitHub!

10

Page 28: Learning Git with Workflows

GUIs are available

Thanks GitHub!

"Github for Mac"

http://mac.github.com/

10

Page 29: Learning Git with Workflows

GUIs are available

Thanks GitHub!

"Github for Mac"

http://mac.github.com/

"Github for Windows"

http://windows.github.com/

10

Page 30: Learning Git with Workflows

GUIs are available

Thanks GitHub!

"Github for Mac"

http://mac.github.com/

"Github for Windows"

http://windows.github.com/

Other

http://git-scm.com/downloads/guis

10

Page 31: Learning Git with Workflows

Tell Git who you are

11

Page 32: Learning Git with Workflows

Tell Git who you are

$ git config --global user.name "Mosky Liu"

11

Page 33: Learning Git with Workflows

Tell Git who you are

$ git config --global user.name "Mosky Liu"

$ git config --global user.email [email protected]

11

Page 34: Learning Git with Workflows

Other Git configs

12

Page 35: Learning Git with Workflows

Other Git configs

$ git config --global core.editor emacs

12

Page 36: Learning Git with Workflows

Other Git configs

$ git config --global core.editor emacs

$ git config --global merge.tool vimdiff

12

Page 37: Learning Git with Workflows

Other Git configs

$ git config --global core.editor emacs

$ git config --global merge.tool vimdiff

$ git config --list

12

Page 38: Learning Git with Workflows

Other Git configs

$ git config --global core.editor emacs

$ git config --global merge.tool vimdiff

$ git config --list

$ vim ~/.gitconfig

12

Page 39: Learning Git with Workflows

Other Git configs

$ git config --global core.editor emacs

$ git config --global merge.tool vimdiff

$ git config --list

$ vim ~/.gitconfig

http://j.mp/mosky-gitconfig

12

Page 40: Learning Git with Workflows

Core Routine

Page 41: Learning Git with Workflows

Create a repository

14

Page 42: Learning Git with Workflows

Create a repository

$ git init [<directory>]

14

Page 43: Learning Git with Workflows

Commit changes

15

Page 44: Learning Git with Workflows

Commit changes

$ git add <file> ...

15

Page 45: Learning Git with Workflows

Commit changes

$ git add <file> ...

$ git commit

15

Page 46: Learning Git with Workflows

Simplest Workflow

16

Page 47: Learning Git with Workflows

Simplest Workflow

(1) $ git init <directory>

16

Page 48: Learning Git with Workflows

Simplest Workflow

(1) $ git init <directory>(2) (modify file)

16

Page 49: Learning Git with Workflows

Simplest Workflow

(1) $ git init <directory>(2) (modify file)(3) $ git add <file> ...

16

Page 50: Learning Git with Workflows

Simplest Workflow

(1) $ git init <directory>(2) (modify file)(3) $ git add <file> ...(4) $ git commit

16

Page 51: Learning Git with Workflows

Simplest Workflow

(1) $ git init <directory>(2) (modify file)(3) $ git add <file> ...(4) $ git commit

# Back 2

16

Page 52: Learning Git with Workflows

Simplest Workflow

(1) $ git init <directory>(2) (modify file)(3) $ git add <file> ...(4) $ git commit

# Back 2The end of the core --- it's super easy!

16

Page 53: Learning Git with Workflows

Secondary Routine

Page 54: Learning Git with Workflows

Check status of files

18

Page 55: Learning Git with Workflows

Check status of files

$ git status

18

Page 56: Learning Git with Workflows

Check status of files

$ git status

18

Page 57: Learning Git with Workflows

Check what you changed

19

Page 58: Learning Git with Workflows

Check what you changed

$ git diff

19

Page 59: Learning Git with Workflows

Check what you changed

$ git diff

19

Page 60: Learning Git with Workflows

Check commits

20

Page 61: Learning Git with Workflows

Check commits

$ git log

20

Page 62: Learning Git with Workflows

Check commits

$ git log

20

Page 63: Learning Git with Workflows

Move between commits

21

Page 64: Learning Git with Workflows

Move between commits

$ git checkout <commit>

21

Page 65: Learning Git with Workflows

Move between commits

$ git checkout <commit>

<commit>

599d439fd3813298da16f12ed40f3a0716872c30

599d439

HEAD21

Page 66: Learning Git with Workflows

Name commit

22

Page 67: Learning Git with Workflows

Name commit

$ git tag <tagname>

$ git checkout 599d439

$ git tag v0.1

$ git checkout v0.1

22

Page 68: Learning Git with Workflows

Reset to a commit

23

Page 69: Learning Git with Workflows

Reset to a commit

$ git reset <commit>

Reset HEAD to <commit>.

23

Page 70: Learning Git with Workflows

Make a "reverse" commit

24

Page 71: Learning Git with Workflows

Make a "reverse" commit

$ git revert <commit>Apply a "reverse" commit.

24

Page 72: Learning Git with Workflows

Reset to a commit

25

Page 73: Learning Git with Workflows

Reset to a commit

26

Page 74: Learning Git with Workflows

Make a "reverse" commit

27

Page 75: Learning Git with Workflows

Make a "reverse" commit

28

Page 76: Learning Git with Workflows

Branching

Page 77: Learning Git with Workflows
Page 78: Learning Git with Workflows
Page 79: Learning Git with Workflows
Page 80: Learning Git with Workflows
Page 81: Learning Git with Workflows
Page 82: Learning Git with Workflows
Page 83: Learning Git with Workflows
Page 84: Learning Git with Workflows
Page 85: Learning Git with Workflows

master

Page 86: Learning Git with Workflows

master

topic

Page 87: Learning Git with Workflows

master

topic

HEAD

Page 88: Learning Git with Workflows

master

topic

HEAD

Page 89: Learning Git with Workflows

master

topic

HEAD

Page 90: Learning Git with Workflows

master

topic

HEAD

Page 91: Learning Git with Workflows

master

topic

HEAD

Page 92: Learning Git with Workflows

Create a branch

32

Page 93: Learning Git with Workflows

Create a branch

$ git branch <branchname>

32

Page 94: Learning Git with Workflows

Create a branch

$ git branch <branchname>

$ git checkout <branchname>

32

Page 95: Learning Git with Workflows

Create a branch

$ git branch <branchname>

$ git checkout <branchname>or

32

Page 96: Learning Git with Workflows

Create a branch

$ git branch <branchname>

$ git checkout <branchname>or

$ git checkout -b <branchname>

32

Page 97: Learning Git with Workflows

Delete and list branch(es)

33

Page 98: Learning Git with Workflows

Delete and list branch(es)

$ git branch -d <branchname>Delete branch.

33

Page 99: Learning Git with Workflows

Delete and list branch(es)

$ git branch -d <branchname>Delete branch.

$ git branchList branches.

33

Page 100: Learning Git with Workflows

Move between branches

34

Page 101: Learning Git with Workflows

Move between branches

$ git checkout <branchname>

34

Page 102: Learning Git with Workflows

Merge a branch back

35

Page 103: Learning Git with Workflows

Merge a branch back

$ git checkout <base-branch>

35

Page 104: Learning Git with Workflows

Merge a branch back

$ git checkout <base-branch>

$ git merge <topic-branch>

35

Page 105: Learning Git with Workflows
Page 106: Learning Git with Workflows

Branching Workflow

37

Page 107: Learning Git with Workflows

Branching Workflow

...

37

Page 108: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

37

Page 109: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

37

Page 110: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

(3) (modify file)

37

Page 111: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

(3) (modify file)

...

37

Page 112: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

(3) (modify file)

...

(4) $ git commit

37

Page 113: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

(3) (modify file)

...

(4) $ git commit

# Back 3 until finish "topic"

37

Page 114: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

(3) (modify file)

...

(4) $ git commit

# Back 3 until finish "topic"

(5) $ git checkout <base-branch>

37

Page 115: Learning Git with Workflows

Branching Workflow

...

(1) $ git branch <topic-branch>

(2) $ git checkout <topic-branch>

(3) (modify file)

...

(4) $ git commit

# Back 3 until finish "topic"

(5) $ git checkout <base-branch>

(6) $ git merge <topic-branch>

37

Page 116: Learning Git with Workflows

Remote Repository

Page 117: Learning Git with Workflows

Clone a remote repository

39

Page 118: Learning Git with Workflows

Clone a remote repository

$ git clone <repos> <dir>

39

Page 119: Learning Git with Workflows

Clone a remote repository

$ git clone <repos> <dir>

<repos>

https://github.com/torvalds/linux.git

39

Page 120: Learning Git with Workflows

Create a remote repository

40

Page 121: Learning Git with Workflows

Create a remote repository

$ git init --bare

40

Page 122: Learning Git with Workflows

Create a remote repository

$ git init --bareor

40

Page 123: Learning Git with Workflows

Create a remote repository

$ git init --bareor

https://github.com/repositories/new

40

Page 124: Learning Git with Workflows

Add, remove and list remotes

41

Page 125: Learning Git with Workflows

Add, remove and list remotes

$ git remote add <name> <url><url> can be a local path.

41

Page 126: Learning Git with Workflows

Add, remove and list remotes

$ git remote add <name> <url><url> can be a local path.

$ git remote remove <name>

41

Page 127: Learning Git with Workflows

Add, remove and list remotes

$ git remote add <name> <url><url> can be a local path.

$ git remote remove <name>

$ git remote

41

Page 128: Learning Git with Workflows

Push commits to remote

42

Page 129: Learning Git with Workflows

Push commits to remote

$ git push <repos> <refspec>...

42

Page 130: Learning Git with Workflows

Push commits to remote

$ git push <repos> <refspec>...

<refspec>usually is branch or tag name

[+]<src>[:<dst>]

:<dst> to delete remote reference.

42

Page 131: Learning Git with Workflows

Pull commits from remote

43

Page 132: Learning Git with Workflows

Pull commits from remote

$ git pull <repos> <refspec>...

43

Page 133: Learning Git with Workflows

A Co-working Workflow

Page 134: Learning Git with Workflows

Three Principles

45

Page 135: Learning Git with Workflows

Three Principles

1. master is production.

45

Page 136: Learning Git with Workflows

Three Principles

1. master is production.

2. dev only includes stable and reviewed code.

45

Page 137: Learning Git with Workflows

Three Principles

1. master is production.

2. dev only includes stable and reviewed code.

3. Create topic branch to resolve issue all the time.

45

Page 138: Learning Git with Workflows

Three Phases

46

Page 139: Learning Git with Workflows

Three Phases

1. Resolving

Create a topic branch to resolve issue.

46

Page 140: Learning Git with Workflows

Three Phases

1. Resolving

Create a topic branch to resolve issue.

2. Reviewing

Review the code.

46

Page 141: Learning Git with Workflows

Three Phases

1. Resolving

Create a topic branch to resolve issue.

2. Reviewing

Review the code.

3. Cleanup

Merge into dev and remove topic branch.

46

Page 142: Learning Git with Workflows

47

Page 143: Learning Git with Workflows

Assigner: "We need to resolve this issue."

47

Page 144: Learning Git with Workflows

Assigner: "We need to resolve this issue."

Assignee: "Yes, sir!"

47

Page 145: Learning Git with Workflows

Assigner: "We need to resolve this issue."

Assignee: "Yes, sir!"

Assignee (dev) $ git checkout -b topic

47

Page 146: Learning Git with Workflows

Assigner: "We need to resolve this issue."

Assignee: "Yes, sir!"

Assignee (dev) $ git checkout -b topic

Assignee (topic) $ (commit...)

47

Page 147: Learning Git with Workflows

Assigner: "We need to resolve this issue."

Assignee: "Yes, sir!"

Assignee (dev) $ git checkout -b topic

Assignee (topic) $ (commit...)

Assignee (topic) $ git push origin topic

47

Page 148: Learning Git with Workflows

Assigner: "We need to resolve this issue."

Assignee: "Yes, sir!"

Assignee (dev) $ git checkout -b topic

Assignee (topic) $ (commit...)

Assignee (topic) $ git push origin topic

Until resolve, call assigner for review.

47

Page 149: Learning Git with Workflows

48

Page 150: Learning Git with Workflows

Assignee: "I resolved!"

48

Page 151: Learning Git with Workflows

Assignee: "I resolved!"

Assigner: "Let me review."

48

Page 152: Learning Git with Workflows

Assignee: "I resolved!"

Assigner: "Let me review."

Assigner (dev) $ git checkout -b topic

48

Page 153: Learning Git with Workflows

Assignee: "I resolved!"

Assigner: "Let me review."

Assigner (dev) $ git checkout -b topic

Assigner (topic) $ git pull origin topic

48

Page 154: Learning Git with Workflows

Assignee: "I resolved!"

Assigner: "Let me review."

Assigner (dev) $ git checkout -b topic

Assigner (topic) $ git pull origin topic

Assigner (topic) $ git diff ...dev

48

Page 155: Learning Git with Workflows

Assignee: "I resolved!"

Assigner: "Let me review."

Assigner (dev) $ git checkout -b topic

Assigner (topic) $ git pull origin topic

Assigner (topic) $ git diff ...dev

If it is not good enough, call assignee to fix.

48

Page 156: Learning Git with Workflows

49

Page 157: Learning Git with Workflows

Assigner (topic) $ git checkout dev

49

Page 158: Learning Git with Workflows

Assigner (topic) $ git checkout dev

Assigner (dev) $ git merge topic

49

Page 159: Learning Git with Workflows

Assigner (topic) $ git checkout dev

Assigner (dev) $ git merge topic

Assigner (dev) $ git push origin dev

49

Page 160: Learning Git with Workflows

Assigner (topic) $ git checkout dev

Assigner (dev) $ git merge topic

Assigner (dev) $ git push origin dev

Assigner: "Good job!"

49

Page 161: Learning Git with Workflows

Assigner (topic) $ git checkout dev

Assigner (dev) $ git merge topic

Assigner (dev) $ git push origin dev

Assigner: "Good job!"

Assignee (dev) $ git branch -d topic

49

Page 162: Learning Git with Workflows

Assigner (topic) $ git checkout dev

Assigner (dev) $ git merge topic

Assigner (dev) $ git push origin dev

Assigner: "Good job!"

Assignee (dev) $ git branch -d topic

Assignee (dev) $ git push origin :topic

49

Page 163: Learning Git with Workflows

Assigner (topic) $ git checkout dev

Assigner (dev) $ git merge topic

Assigner (dev) $ git push origin dev

Assigner: "Good job!"

Assignee (dev) $ git branch -d topic

Assignee (dev) $ git push origin :topic

Assignee (dev) $ git pull origin dev49

Page 164: Learning Git with Workflows
Page 165: Learning Git with Workflows

End

Page 166: Learning Git with Workflows

End

52

Page 167: Learning Git with Workflows

End

Use branch!

52

Page 168: Learning Git with Workflows

End

Use branch!

Workflow does matter.

52

Page 169: Learning Git with Workflows

End

Use branch!

Workflow does matter.

Git still has many magics.

52

Page 170: Learning Git with Workflows

End

Use branch!

Workflow does matter.

Git still has many magics.

Tips: http://j.mp/mosky-gitconfig

52

Page 171: Learning Git with Workflows

End

Use branch!

Workflow does matter.

Git still has many magics.

Tips: http://j.mp/mosky-gitconfig

Q&A

52