Git Party
Git Party
1 / 37
2 / 37
Common operations
Workows
3 / 37
Outline
What makes a distributed VCS Common operations Workows Fun with git
4 / 37
Indepentent instances
every copy of the repository is standalone no central server, no one true version democracy at its best!
5 / 37
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
6 / 37
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
7 / 37
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 "[email protected]" color.diff true color.status true color.branch true color.ui true
8 / 37
Common operations
Outline
What makes a distributed VCS Common operations Workows Fun with git
9 / 37
Common operations
Checking in changes
Modify les, register changes $ sed $ git ... # ... $ git $ git $ git -i s/advanced/awesome/ README status modified: README
10 / 37
Common operations
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
11 / 37
Common operations
Moving changes between the index and the working area $ $ $ $ $ $ git git git git git git add -p status reset status checkout README status
12 / 37
Common operations
13 / 37
Common operations
a branch is a chain of commits a tag is a pointer to a single commit branches are quick and cheap to create
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
15 / 37
Common operations
A visual example
e a (...) c d e'
16 / 37
Common operations
Forensics
all history is stored locally, of course makes consulting it very quick powerful ways of consulting the history
17 / 37
Common operations
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
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
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
20 / 37
Workows
Outline
What makes a distributed VCS Common operations Workows Fun with git
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
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 [email protected]:pg.git cd pg-clone1 git remote git branch -r
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
24 / 37
Workows
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
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
26 / 37
Workows
d a b c d'
e'
27 / 37
Workows
d a b c d'
e f e'
28 / 37
Workows
d'
e'
29 / 37
Workows
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
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
32 / 37
Workows
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
33 / 37
Outline
What makes a distributed VCS Common operations Workows Fun with git
34 / 37
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
35 / 37
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
37 / 37