Why You Should Be Using Git

Embed Size (px)

Citation preview

Black and White

Why you should be using

Francisco Vieira

with very high probability...

Disable Take a Break!!!

What is git?

VCS

Open source

Distributed

Offline

Fast

Flexible

Complex

Not SVN

- Not something you are going to fully understand in an hour- Dont try to map your understanding of subversion onto git

Command Glossary

Init Create a repository

Clone Clone a repository (svn checkout)

Commit Offline commit

Merge

Pull Download changes from remote repo (svn update)

Push Upload changes to remote repo (svn does this on each commit)

git is...

DISTRIBUTED

Centralized

Distributed

Backups

Offlineoperations

Fast

Multipleworkflowspossible

- No need for a connection anywhere- (Online) Push and pull- John testa o software em vrios sistemas operativos

Distributed Workflows
Centralized

Distributed Workflows
Github-like

git init

Distributed Workflows
Github-like

git clone

Distributed Workflows
Github-like

git commit

Distributed Workflows
Github-like

git push

Distributed Workflows
Github-like

git clone

Distributed Workflows
Github-like

git clone

Distributed Workflows
Github-like

git commit

Distributed Workflows
Github-like

git push

Distributed Workflows
Github-like

Pull Request

Distributed Workflows
Github-like

git pull

Distributed Workflows
Github-like

git push

Distributed Workflows
Github-like

git has...

A STAGING AREA

Staging Area

Staging Area

Staging Area Example

Staging Area Example

git has...

EASY BRANCHING

Branching

2fbc...3fab...b99d...

Setas no representam direco do tempo.Explicar SHA1 (20 bytes, 40 char)

Branching

123

Branching

123

master

Branching

123

master

HEAD

Branching

1243

master

HEAD

git commit

Branching

1243

master

HEAD

feature

git branch feature

Branching

1243

master

HEAD

feature

git checkout feature

Branching

1243

master

HEAD

feature

5

git commit

Branching

1243

master

HEAD

feature

5

git checkout master

Branching

1243

master

HEAD

feature

5

6

git commit

Branching

1243

master

HEAD

feature

5

6

7

git merge feature

Branching

1243

master

HEAD

5

6

7

git branch -d feature

Git finds merge ancestor automaticallyConflict resolution

Tagging

1243

master

HEAD

Tagging

1243

master

HEAD

v0.1

git tag v0.1

Tagging

1243

master

HEAD

5

6

7

v0.1

Tagging

1243

master

HEAD

5

6

7

v0.1

git checkout v0.1

but...

WHY BRANCHING?!

Typical Release Cycle

Typical Release Cycle

Git
flow

Ateno direco das setas.

Porque feature branches:- se os requisitos mudam e uma feature passa a ser desnessesria, o cdigo relativo feature vai para o lixo. Ento e as outras alteraes feitas a meio da criao da feature (bug-fixes, pequenas refactorizaes)?

Git flow

git init

Hea

Git flow

1master

git commit

HEAD desnecessria. onde ocorre a aco (commit, merge, tag).

Git flow

12

master

git commit

Git flow

12

git commit

3

master

Git flow

12

git tag v0.1

3

master

v0.1

Git flow

12

git branch dev

3

master

v0.1

dev

Branch dev:- Cdigo que vai estar com certeza na prxima release.

Git flow

12

git commit

3

master

v0.1

dev

4

Git flow

12

git commit

3

master

v0.1

4

dev

5

Git flow

12

git branch feature1

3

master

v0.1

4

dev

5

feature1

Vantagens de ter features em branches:- Permite ao developer trabalhar na feature sem ter que se preocupar muito com o resto do desenvolvimento.- Permite visualizar facilmente todas as modificaes que so efectuadas por aquela feature.- Fcil de discartar ideias- Fcil de adiar o lanamento de uma feature para outra release

Git flow

3

master

v0.1

4

dev

5

feature1

...

Git flow

git commit

3

master

v0.1

4

dev

5

feature1

...

6

Git flow

git commit

3

master

v0.1

4

dev

5

feature1

...

6

7

Git flow

git commit

3

master

v0.1

4

5

...

6

feature1

7

dev

8

Git flow

git commit

3

master

v0.1

4

5

...

6

7

feature1

9

dev

8

Git flow

git merge feature1

3

master

v0.1

4

5

...

6

7

feature1

9

dev

8

10

Git flow

git branch -d feature1

3

master

v0.1

4

5

...

6

7

9

dev

8

10

Git flow

3

master

v0.1

4

5

...

6

7

9

dev

8

10

Git flow

git branch release-v1.0

3

master

v0.1

4

5

...

6

7

9

dev

8

10

release-v1.0

S bugfixes no branch release.No dev podemos comear a preparar a prxima release.Este talvez a altura certa para lanar uma verso beta.

Git flow

git commit

3

master

v0.1

4

5

...

6

7

9

dev

8

10

release-v1.0

11

Git flow

git commit

3

master

v0.1

4

5

...

6

7

9

dev

8

10

11

release-v1.0

12

Git flow

git commit

3

master

v0.1

4

5

...

6

7

9

8

10

11

release-v1.0

12

dev

13

Git flow

git merge release-v1.0

3

master

v0.1

4

5

...

6

7

9

8

10

11

release-v1.0

12

dev

13

14

Git flow

git tag v1.0

3

master

v0.1

4

5

...

6

7

9

8

10

11

release-v1.0

12

dev

13

14

v1.0

Git flow

git merge release-v1.0

3

master

v0.1

4

5

...

6

7

9

8

10

11

release-v1.0

12

dev

13

14

v1.0

15

Integrar os bugfixes desta release no desenvolvimento da prxima.

Git flow

git branch -d release-v1.0

3

master

v0.1

4

5

...

6

7

9

8

10

11

12

dev

13

14

v1.0

15

Git flow

3

master

v0.1

4

5

...

6

7

9

8

10

11

12

dev

13

14

v1.0

15

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git commit

16

descoberto um bug em produo que tem que ser resolvido imediatamente!Resolv-lo no branch dev no serve, h l alteraes que no esto prontas para produo!

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git branch hotfix

16

hotfix

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git commit

16

hotfix

17

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git commit

16

17

hotfix

18

Se o hotfix est terminado, qual o prximo passo?merge

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git merge hotfix

16

17

hotfix

18

Fast-forwardNo h commit de merge.

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git tag v1.1

16

17

hotfix

18

v1.1

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git merge hotfix

16

17

hotfix

18

v1.1

19

Git flow

3

master

v0.1

...

12

dev

14

v1.0

15

...

git branch -d hotfix

16

17

18

v1.1

19

Git
flow

Ateno direco das setas.

Porque feature branches:- se os requisitos mudam e uma feature passa a ser desnessesria, o cdigo relativo feature vai para o lixo. Ento e as outras alteraes feitas a meio da criao da feature (bug-fixes, pequenas refactorizaes)?

Git flow at SAPO

Tpicos extra

Repositrio local de backup.

Mudar de repositorio remoto.

Push para dois repositrios diferentes.

Corrigir o ltimo commit.

Stashing.

Rebase.

- Sublime- check_ssl para intra- Intra e github- Commit ammending

Merge

a4c6438b

9ef8

master

0928

e404

branch

HEAD

Merge

a4c6438b

9ef8

master

0928

e404

HEAD

branch

2e71

git merge master

Rebase

a4c6438b

9ef8

master

0928

e404

branch

HEAD

Rebase

a4c6438b

git rebase master

9ef8

master

a431

13d4

branch

HEAD

SHA mudouS usar se no tiver sido publicado.

Outros tpicos

Fazer fix de um bug numa lib que no me pertence

Interactive rebase (Showing the best face to the world, and keeping linear history. I'd kill for this feature)

Cherry picking (Avoids unwanted merges)

Bisecting (Oh boy, I can't count how many times this had saved me)

GUI Clients

git-gui (for commiting) and gitk (for browsing)

Github Client (Windows and Osx)

SourceTree (Osx)

TortoiseGit (Windows)

Gitg (Gnome)

See more here:http://git-scm.com/downloads/guis

References

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

Pro git book - http://git-scm.com/book

Git tutorial - http://gitimmersion.com/

Cheat sheet - http://media.developerforce.com/cheatsheets/SF_GIT_2Pg_HR_V10.pdf

Visual cheatsheet - http://ndpsoftware.com/git-cheatsheet.html

GitHub - https://github.com/

Heroku - http://www.heroku.com/