Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

Gitting things done

Hands-on introduction to git niceties

Jan Urba nski jan@ducksboard.com


Ducksboard

Atlassian Git Party, Madrid, September 25, 2012

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

1 / 37

For those following at home

Getting the slides http://bit.ly/git-party

Git version used $ git --version git version 1.7.10.4

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

2 / 37

What makes a distributed VCS

Common operations

Workows

Fun with git

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

3 / 37

What makes a distributed VCS

Outline

What makes a distributed VCS Common operations Workows Fun with git

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

4 / 37

What makes a distributed VCS

Indepentent instances

every copy of the repository is standalone no central server, no one true version democracy at its best!

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

5 / 37

What makes a distributed VCS

No revision numbers

each repository is independent no central authority to assign revision numbers everything is identied by hashes (commits, les, everything) each hash is built from the objects data and its parents hash both a consistency and a security measure

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

6 / 37

What makes a distributed VCS

Full control over the repository

you have access to everything you can change past versions of les you can change the ownership of commits its free for all, until you start sharing the repo

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

7 / 37

What makes a distributed VCS

Initial setup

Conguring Git $ $ $ $ $ $ git git git git git git config config config config config config --global --global --global --global --global --global user.name "Joe H. Hacker" user.email "joehacker@example.org" color.diff true color.status true color.branch true color.ui true

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

8 / 37

Common operations

Outline

What makes a distributed VCS Common operations Workows Fun with git

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

9 / 37

Common operations

Checking in changes

Modify les, register changes $ sed $ git ... # ... $ git $ git $ git -i s/advanced/awesome/ README status modified: README

diff --word-diff add README commit -m "fix the README"

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

10 / 37

Common operations

Working area, index, repository

working area is whats on your lesystem index is what you are indenting to commit repository is whats committed sounds complicated, but is quite useful

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

11 / 37

Common operations

Using the index

Moving changes between the index and the working area $ $ $ $ $ $ git git git git git git add -p status reset status checkout README status

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

12 / 37

Common operations

Using the stash


Stashing and unstashing changes $ $ $ $ $ $ $ $ $ $ sed git git git git git git git git git -i s/awesome/superb/ README stash stash list stash pop diff stash stash apply stash list checkout . stash drop

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

13 / 37

Common operations

Branches and tags

a branch is a chain of commits a tag is a pointer to a single commit branches are quick and cheap to create

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

14 / 37

Common operations

Using branches
Creating and switching branches $ $ $ $ $ $ $ $ $ $ $ git git git sed git git git cat git sed git branch checkout -b my-tests branch -i s/awesome/great/ README add . commit -m refix the README checkout master README checkout -b my-other-tests -i s/awesome/cool/ README commit -a -m different way to fix the README

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

15 / 37

Common operations

A visual example

e a (...) c d e'

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

16 / 37

Common operations

Forensics

all history is stored locally, of course makes consulting it very quick powerful ways of consulting the history

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

17 / 37

Common operations

Using git log

Trolling in repo history $ $ $ $ $ $ $ $ git log git show git log -p git log --stat git log -- src/pl/plpython time git log --oneline | wc -l git log --grep=Urba[n n]ski git log -p -S int64

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

18 / 37

Common operations

Viewing dierences

Less and more fancy ways of creating dis $ git diff $ git diff master..my-tests $ HASH=$(git log --until master@{1 year ago}.. \ -n 1 --pretty=%H) $ echo $HASH $ git diff --stat $HASH.. $ git log master~100.. -- src/backend/replication $ git diff master~100.. -- src/backend/replication

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

19 / 37

Common operations

Bisecting
Tracking down a behaviour change $ $ [ ! $ $ $ $ $ $ cat src/backend/catalog/sql_features.txt cat cat ~/bisect.sh -f src/backend/catalog/sql_features.txt ] || exit 125 grep -q ^T131.*YES src/backend/catalog/sql_features.txt git bisect start master 1b3d400cac1 git bisect run ~/bisect.sh git show 294e7945 git blame src/backend/catalog/sql_features.txt g show 294e7945^:src/backend/catalog/sql_features.txt g show 294e7945:src/backend/catalog/sql_features.txt

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

20 / 37

Workows

Outline

What makes a distributed VCS Common operations Workows Fun with git

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

21 / 37

Workows

Remote repositories

a remote is a pointer to a dierent repository you can push your commits to a remote or you can pull commits from a remote to your local repository otherwise, its just like a branch

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

22 / 37

Workows

Cloning a repository

Ways of cloning an existing repository $ $ $ $ $ $ $ $ cd /tmp git clone pg-clone1 ~/src/pg git clone pg-clone2 ~/src/pg git clone http://git.wulczer.org/repos/git-party.git # git clone username@example.org:pg.git cd pg-clone1 git remote git branch -r

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

23 / 37

Workows

Adding commits
Pushing commits upstream $ $ $ $ $ $ $ $ $ cd /tmp/pg-clone1 git checkout --track origin/my-tests git branch git wtf sed -i s/PostgreSQL/Postgres/g README git add . git commit -m change project name git wtf git push

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

24 / 37

Workows

Fetching upstream changes

Pulling changes from upstream $ $ $ $ $ $ $ cd /tmp/pg-clone2 git checkout --track origin/my-tests git wtf git fetch git wtf git log origin/my-tests git merge origin/my-tests

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

25 / 37

Workows

Merging vs rebasing

if only upstream has new commits, straightforward if both upstream and you have commits, needs a decision either perform a merge or rebase your commits

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

26 / 37

Workows

Merging vs rebasing - before merging

d a b c d'

e'

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

27 / 37

Workows

Merging vs rebasing - after merging

d a b c d'

e f e'

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

28 / 37

Workows

Merging vs rebasing - after rebasing

d'

e'

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

29 / 37

Workows

Merging and conicts


Creating a conict $ $ $ $ $ $ $ $ $ cd /tmp/pg-clone1 sed -i s/http/https/g README git add . git commit -m improving security git push cd /tmp/pg-clone2 sed -i s/information/info/g README git add . git commit -m be more concise

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

30 / 37

Workows

Merging changes
Resolving a conict when merging $ git push ! [rejected] HEAD -> my-tests (non-fast-forward) $ git log origin/my-tests $ git fetch $ git log origin/my-tests $ git wtf $ git pull CONFLICT (content): Merge conflict in README $ $EDITOR README $ git add README $ git commit $ git log --graph
Jan Urba nski (Ducksboard) Gitting things done Atlassian Git Party 2012 31 / 37

Workows

Merging changes cont.

Resolving a conict when rebasing $ git reset ORIG_HEAD $ git checkout README $ git rebase origin/my-tests CONFLICT (content): Merge conflict in README $ $EDITOR README $ git add README $ git rebase --continue $ git log --graph

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

32 / 37

Workows

Merging changes cont.

Autoresolved conicts $ $ $ $ $ $ git sed git git git git reset --hard origin/my-tests^ -i s/Postgres/pg/g README add . commit -m be more concise pull --rebase push

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

33 / 37

Fun with git

Outline

What makes a distributed VCS Common operations Workows Fun with git

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

34 / 37

Fun with git

Custom commands

Aliases, manual cong editing $ $ $ $ $ $ git git git git cat cat config --global alias.st status config --global alias.ci commit config --global alias.cdiff diff --cached wtf ~/.gitconfig ~/src/pg/.git/config

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

35 / 37

Fun with git

Rewriting history
Fixing old commits before pushing $ $ $ $ $ $ $ $ $ $ $ $ git sed git git sed git git sed git git git cat ci --amend -i s/supported/usefull/ README add README ci -m change README -i s/Post/post README add README ci -m change case in product name -i s/usefull/useful/ README add README ci -m fix ortography, oh the shame! rebase -i origin/master ~/bin/git-fixup
Gitting things done Atlassian Git Party 2012 36 / 37

Jan Urba nski (Ducksboard)

Fun with git

Thanks! Questions? Lets grab a beer.

Jan Urba nski (Ducksboard)

Gitting things done

Atlassian Git Party 2012

37 / 37

You might also like