intro to git

92
introduction to and

Upload: romain-prieto

Post on 15-Aug-2015

37 views

Category:

Technology


1 download

TRANSCRIPT

introduction to

and

GIT COMMITS

local files

the staging area

first commit

second commit

parent

just a “patch”of what actually

changed

third commit

parent

parent

unique identifiers (sha)

ab67d9c

40fc3a7

be89a10

multiple parents and children = source graphs

branching out

ab67d9c

40fc3a7

be89a10

5e94ba2

f3c091d

merging back

ab67d9c

40fc3a7

783ad20

5e94ba2

f17cc43

WORKING WITHREMOTES

MASTER(by convention)

your computer github (a.k.a “origin”)

master master

Github is moving along...

your computer github

master

master

your computer github

master

master

let’s update our local copy

$ git fetch origin master

your computer github

master

masterorigin/master

$ git status -uno

Your branch is behind 'origin/master' by 2 commits and can be fast-forwarded

$ git merge origin/master

your computer github

master origin/master master

Fast-forwards are easy :)

Now another case...

your computer github

master master

your computer github

master

master

your computer github

master master

let’s update our local copy

$ git fetch origin master

your computer github

master mastero/m

$ git status -uno

Your branch and 'origin/master' have diverged,

and have 2 and 2 different commits each

$ git merge origin master

your computer github

master

o/m master

this created a new “merge” commit

we need to send it back to Github

$ git push origin master

your computer github

master masterorigin/master

but I don’t like merge commits!

your computer github

master mastero/m

$ git rebase origin/master

your computer github

x

origin/master master

your computer github

x

masterorigin/master

your computer github

master

masterorigin/master

we’re back to a linear history!

$ git status -uno

Your branch is ahead of 'origin/master' by 2 commits

$ git push origin master

your computer github

master masterorigin/master

careful: we actually re-wrote history!

only do this if no one has seen your commits yet

BRANCHES

your computer

master

$ git checkout -b foo

it's just a pointer

foo HEADmaster

HEAD is a pointer to where you are

working on your branch

foo HEAD

master

$ git checkout master

back on master…

foo

HEAD master

and working some more

fooHEAD master

and what about our remotes?

foomasterorigin/master

the origin doesn’t know about "foo"

$ git push origin foo

so “master” was just another branch!

origin/foofoomasterorigin/master

now while we’re on master

$ git merge foo

foo

HEAD master

looks familiar?

yes, that’s a merge commit

$ git branch -d foo

we just deleted the branch pointer

HEAD master

PULL REQUESTS

asking the “owner” to merge a set of your commits

(typically a given branch)

this branch is ready for review / integration

master my-branch

merged!

master“merged

pull request”

what if there is a conflict?

$ git checkout my-branch

resolve it on your branch

master my-branch HEAD

$ git merge master

first: resolve it

master

my-branch HEAD

“resolved conflict”

“mergedpull request”

master

“resolved conflict”

or we could have rebased to avoid the extra

“resolve conflict” commit

FORKS

you might not have permission to create branches

in someone else’s repository

or even if you do... it could get messy

mary’s refactor

master

mary’s fix

john’s feature

john’s test

a fork is your copy of a repo

your fork clean “upstream”

master fix2

fix1

origin/fix2

origin/master

master

just one more pointer to keep in mind

$ git fetch upstream master

fix

origin/fix

upstream/master

you can submit a pull request straight from your fork

fork (local)

upstream

fork (origin)

pull request

merge

push branch

TOOLS& RESOURCES

http://git-scm.com/downloads

$ brew install git

or

http://pragprog.com/book/tsgit/pragmatic-version-control-using-git

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

https://www.atlassian.com/git/tutorial/git-basics

http://try.github.io/

The end.