git and github

68
git and github darren oakley

Upload: darren-oakley

Post on 06-May-2015

4.268 views

Category:

Technology


0 download

DESCRIPTION

A short and basic introduction to git and github that I gave at the Sanger Institute on the 15th Dec 2009.

TRANSCRIPT

Page 1: git and github

git and githubdarren oakley

Page 2: git and github

disclaimer

• i use git daily in my work and manage to not have many problems

• i’ve been asked to share the basics i know with others

• i am not a git expert - i may (most probably) not be able to answer all of your questions

Page 3: git and github

what we’ll cover

• brief discussion on version control - ‘traditional’ v’s distributed

• git - the basics

• github - the basics

Page 4: git and github

what we won’t cover

• advanced git

• rebase

• sub-modules

• git-svn

Page 5: git and github

version control

Page 6: git and github

version control

• what most people are (probably) used to:

• concurrent version system (cvs)

• subversion (svn)

Page 7: git and github

version control

• cvs and svn

• central source control server

• users check code into server

• requires connection to the server to perform commits, updates etc.

Page 8: git and github

distributed version control

• the new hotness...

• git

• mercurial (hg)

• bazaar (bzr)

Page 9: git and github

what’s the difference?

• not a lot really...

• you store a complete copy of a repository within your working copy

• this means you can work offline

• there is no default ‘central’ server - if you want one, you (and your team) just nominate where it is (i.e. a github)

Page 10: git and github

git

Page 11: git and github

getting started

• move to a directory with code you’d like to manage with git:

git init

• you’ve now created your first git repository!

Page 12: git and github

normal workflow

Page 13: git and github

local operations

working directory

stagingarea

git directory(repsoitory)

checkout the project

stage files

commit

Page 14: git and github

staging files

git add [filenames]

• add all changed files to the staging area:

git add .

• these changes are NOT committed yet

Page 15: git and github

the git staging area

• git has a concept of a ‘staging area’

• you first stage all of the changes that you are happy with

• then you commit them

Page 16: git and github

isn’t this more work?

• in short - yes

• but it allows you to craft the exact commit you want - you eventually get to love this feature

• you can get around it if you like...

Page 17: git and github

committing

git commit -m “commit message”

git commit -a -m “commit message”

Page 18: git and github

branching / merging

Page 19: git and github

branching

git branch

git branch [new branch name]

git checkout [new branch name]

Page 20: git and github

merging

git checkout [target branch]

git merge [other branch]

git merge --squash [other branch]

Page 21: git and github

rewriting history

git rebase

• will leave that as an exercise for you to investigate...

Page 22: git and github

remote operations

Page 23: git and github

remote repositories

git push [repository] [repository branch]

git pull [repository] [repository branch]

Page 24: git and github

remote operations

user one

user two

repository(github)

repository(internal)

user

user

user

example - group using open source code internally with modifications specific to them can easily push/pull from the project ‘master’

Page 25: git and github

some rules i tend to follow...

Page 26: git and github

• NEVER pull when you have uncommitted changes - commit your work first

• if working on a feature, use a local branch, then this leaves the master open for other fixes

• NEVER rebase or amend commits that you have pushed

Page 27: git and github

• simply...

• ‘pull’ at the start of the day and at regular intervals (as often as you’d checkout your code in cvs/svn)

• ‘push’ after every commit

If you want it to work like cvs / svn

Page 28: git and github

github

Page 29: git and github

github

• http://github.com

• popular git repository hosting site

• home to many open source projects:

• ruby on rails, jquery to name two...

Page 30: git and github

a quick hands-on with github

Page 31: git and github

the plan...

• get yourselves into pairs

• person 1:

• create a repository

• check in some code

• add person 2 to project

Page 32: git and github

the plan...

• person 2:

• pull code from person 1’s repository

• make some changes and push back to repository

• person 1:

• pull these changes

Page 33: git and github

the plan...

• somebody:

• tag a release of the code

• push this tag to github

• stare in awe at the auto-generated tarball

Page 34: git and github

if we have time...

• person 1:

• create a local branch of the code

• push this branch to github

• person 2:

• pull and work with this remote branch

Page 35: git and github

if we have more time

• simulate a conflict and resolve it

Page 36: git and github

let’s get going...

Page 37: git and github

person 1

Page 38: git and github
Page 39: git and github
Page 40: git and github
Page 41: git and github
Page 42: git and github
Page 43: git and github

person 2

Page 44: git and github
Page 45: git and github

git clone [paste ‘your clone url’]

edit something

add and commit

git push origin master

Page 46: git and github

person 1

Page 47: git and github

git pull origin master

see if you have the changes from your partner

Page 48: git and github

somebody

Page 49: git and github

git tag rel_1.0

git push --tags

Page 50: git and github
Page 51: git and github
Page 52: git and github

do we have time?

Page 53: git and github

person 1

Page 54: git and github

git branch new_feature_foo

git checkout new_feature_foo

edit something, add and commit

git push origin new_feature_foo

Page 55: git and github

person 2

Page 56: git and github

git remote show origin

git fetch origin new_feature_foo:new_feature_foo

git fetch [repo] [remote_branch]:[local_branch]

Page 57: git and github

edit something, add and commit

git push origin new_feature_foo

cat .git/config

- info on repository setup

Page 58: git and github
Page 59: git and github

simulating a conflict

Page 60: git and github

person 1

Page 61: git and github

without doing a git pull!

edit the file that person 2 just edited

save, add and commit changes

git push origin new_feature_foo

O_o ooops...

Page 62: git and github

git pull origin new_feature_foo

(git will inform you of a conflict)

edit the file - resolve the conflict

git add, commit, push

conflict resolved! ^_^

Page 63: git and github

further reading

• http://git-scm.com/documentation

• http://learn.github.com/

• http://help.github.com/

• http://www.gitready.com/

Page 64: git and github

further reading

Page 65: git and github

git configsome setup i find useful...

Page 66: git and github

git config --global color.diff auto

git config --global color.status auto

git config --global color.branch auto

git config --global color.interactive auto

Page 67: git and github

git config --global alias.st status

git config --global alias.ci commit

git config --global alias.co checkout

git config --global alias.br branch

Page 68: git and github

git config --global core.excludesfile ~/.gitignore

echo "*~" >~/.gitignore

echo ".DS_Store" >>~/.gitignore