a handful of git workflows for the agilist · :feature> git commit -am Ôdid something...

21
a handful of Git workflows for the agilist steven harman twitter: stevenharman http://stevenharman.net

Upload: others

Post on 23-Jun-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

a handful of Git workflows for the

agilist

steven harmantwitter: stevenharman

http://stevenharman.net

Page 2: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

stop worrying and start

loving The Git.

git is awesome - if you’re using it, you know. if not, don’t be scared, give it a try.

Page 3: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

picture Git

don’t be scared, it’s not as bad as it looks.

Page 4: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

basic branch/feature workflow

Page 5: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

let’s assume there already exists a Git repository somewhere in the cloud. like maybe... The GitHub.

Page 6: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

:> git clone [email protected]:stevenharman/foo.git:> cd foo:master>

start by cloning a copy of that remote repository (conventionally known as “origin”) to our local machine.

Page 7: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

:master> git checkout -b feature:feature> [... hackity-hack-hack ...]:feature> git commit -am ‘did something awesome.’

we need to work a sweet new feature. step 1) create a local branch to work in. step 2) hackity-hack-hack. step 3) commit the changes. [repeat steps 2 & 3 as necessary]

Page 8: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

// someone else pushed a change to the remote.

a teammate, or maybe even another you, has pushed some new changes.

Page 9: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

:feature> [... more hackity-hack-hack ...]:feature> git commit -am ‘more awesomeness. bacon!’

[still continuing steps 2 & 3 from earlier]

Page 10: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

:feature> git fetch origin

get any new changes that are on the remote, but not local.

Page 11: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

:feature> git checkout master:master> git merge origin/master

merge the changes from the remote “master” branch into our local “master” branch. because there are no divergent changes on our local master, this is a “fast-forward merge” along the master’s graph.

Page 12: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

local Git repository (your clone)

master

featureorigin/master

:master> git merge feature

now we need to merge our feature into “master” so we can release it.

option 1) merge feature in. [keeps all info, but we end up with a noisy history graph that’s hard to follow]

Page 13: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

OR [go back to just after we merged in the fetched changes]

Page 14: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

local Git repository (your clone)

master

featureorigin/master

local Git repository (your clone)

master

feature

origin/master

:master> git checkout feature:feature> git rebase master

option 2) rebase our “feature” branch on top of “master”.

this “rewinds” our branch back to where it started, then “fast-forwards” along “master”, and finally re-applies each of our change sets. afterward, our local commits have a new SHA1 hash, meaning they are different objects than before rebase, however, the original committer info & meta-data are preserved.

Page 15: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

local Git repository (your clone)

master

featureorigin/master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

masterfeature

origin/master

:feature> git checkout master:master> git merge feature

now we can merge our changes into “master.” because we already have all of the changes that exist in “master,” this results in a “fast-forward” merge onto “master”.

Page 16: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

local Git repository (your clone)

master

featureorigin/master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

masterfeature origin/master

:master> git push origin master

finally we share our sweet, sweet bacon with the rest of the world by pushing our local changes to the remote (origin).

Page 17: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

master

origin/masterfeature

local Git repository (your clone)

masterfeature

origin/master

local Git repository (your clone)

master

featureorigin/master

local Git repository (your clone)

master

feature

origin/master

local Git repository (your clone)

masterfeature

origin/master

remote Git repository (origin)

master

local Git repository (your clone)

masterfeature origin/master

remote Git repository (origin)

master

local Git repository (your clone)

master origin/master

:master> git branch -d feature

now everyone can enjoy the bacony-goodness!

Page 18: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

derivations

• branch for a spike

• branches for concurrent design

• push/pull changes directly from teammate

• stashing changes temporarily

• reset to prior commit (in case of FUBAR)

Page 19: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

some cool tools for your Git utility belt• git reset

• git cherry-pick

• git stash

• git bisect

• git add -p

• git reflog

• git svn

add -p to interactively stage hunks of a file change.

Page 20: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

get Git info

• http://ProGit.org (the site for THE book)

• http://gitready.com

• http://gitcasts.com

• http://whygitisbetterthanx.com/

• http://delicious.com/stevenharman/git

Page 21: a handful of Git workflows for the agilist · :feature> git commit -am Ôdid something awesome.Õ we need to work a sweet new feature. step 1) create a local branch to work in. step

steven harmantwitter: stevenharman

http://stevenharman.net

fork these slides from http://github.com/stevenharman/git-workflows

feel free to hit me up with any questions.