Slide 1

Slide 1 text

Git from scratch Xabier Larrakoetxea @slok69

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Some background

Slide 4

Slide 4 text

Subversion CVS Team Foundation ... VCS Server Repo User 1 Project User 2 Project User N Project Version Control System

Slide 5

Slide 5 text

Git Mercurial Bazaar ... DVCS Server Repo User 1 Repo User 2 Repo User N Repo Distributed Version Control System

Slide 6

Slide 6 text

Git uses snapshots not diffs File 1 Version 1 File 2 File 3 File 4 File 1 Version 2 File 2 File 3 File 4 Version 3 File 2 File 3 File 4 Version 4 File 2 File 3 File 1 File 1 File 4

Slide 7

Slide 7 text

The zones 3

Slide 8

Slide 8 text

Working directory Staging area Git directory (repo) Remote Git directory (repo) Stage files Checkout Project Commit Push changes

Slide 9

Slide 9 text

Working directory Staging area Git directory (repo) Remote Git directory (repo) Stage files Checkout Project Commit Push changes WTF is this?!

Slide 10

Slide 10 text

Untracked Unmodified Modified Staged Add file Stage file Commit Edit file Remove file

Slide 11

Slide 11 text

Git internals

Slide 12

Slide 12 text

Git File types Commit Tree Author Comitter Tree Blob Blob Blob Blob Print(“Hello world”) Blob package main import( “fmt” ) Blob README HI!

Slide 13

Slide 13 text

SSH FS HTTP/S Git Git Protocols

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Configuration

Slide 16

Slide 16 text

--system /etc/gitconfig --global $HOME/.gitconfig $GIT_REPO/.git/config Configuration levels

Slide 17

Slide 17 text

$ git config --global user.name “Alex Murphy” --global user.mail [email protected] --global color.ui true

Slide 18

Slide 18 text

Ignoring files https://github.com/github/gitignore # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging bin/ build/ develop-eggs/ dist/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging bin/ build/ develop-eggs/ dist/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .gitignore

Slide 19

Slide 19 text

Git basics

Slide 20

Slide 20 text

$ git init /home/robocop/pybot --bare /home/robocop/pybot

Slide 21

Slide 21 text

$ git clone https://[email protected]/rbcop/pybot.git [email protected]:ticketbis/tickets.git -b develop [email protected]:ticketbis/t.git

Slide 22

Slide 22 text

$ git add bot/__init__.py tests/ --patch bot/run.py -A .

Slide 23

Slide 23 text

$ git rm bot/__init__.py tests/

Slide 24

Slide 24 text

$ git mv bot/test.py /bot/tests.py

Slide 25

Slide 25 text

Repo status $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: queueworkers/settings.py # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: queueworkers/logging.conf # modified: queueworkers/utils/logs.py # # Untracked files: # (use "git add ..." to include in what will be committed) # # queueworkers/test

Slide 26

Slide 26 text

$ git diff --stat HEAD^^^ HEAD run.py master origin/master --cached

Slide 27

Slide 27 text

Repo Diffs diff --git a/queueworkers/utils/messageimporter.py b/queueworkers/utils/messageimporter.py index 8c5e904..fe57a72 100644 --- a/queueworkers/utils/messageimporter.py +++ b/queueworkers/utils/messageimporter.py @@ -12,8 +12,8 @@ def exec_publisher(publisher, body, channel, method): try: publisher.connect() publisher.publish(body) - if settings.SEND_ACK: - channel.basic_ack(delivery_tag=method.delivery_tag) + #if settings.SEND_ACK: + # channel.basic_ack(delivery_tag=method.delivery_tag) except Exception as e: logger.error("Exception: " + str(e)) raise $ git diff

Slide 28

Slide 28 text

$ git commit -m “Initial commit” -avm “Fucking templates” http://whatthecommit.com

Slide 29

Slide 29 text

commit -a shortcut Working directory Staging area Repository $ Git add $ Git commit Working directory Staging area Repository $ Git commit -a

Slide 30

Slide 30 text

$ git log --graph --decorate --oneline --stat -n 3 --all

Slide 31

Slide 31 text

Repo log * 3b3eac4 (HEAD, branch2) Edited README3 in branch2 | * 77c48e7 (master) Merge branch 'branch2' | |\ | |/ |/| * | 3699398 Modified README 3 in branch2 | * 3cc6283 Modified README 3 in master branch |/ * 736c954 Modified README 3 * 56dedf6 Modified README 1 and 2 * c2f5d57 Initial commit $ git log --graph --decorate --oneline --all http://garmoncheg.blogspot.com.es/2012/06/pretty-git-log.html

Slide 32

Slide 32 text

Remote

Slide 33

Slide 33 text

$ git remote -v add origin [email protected]/slok/go-copy rm origin

Slide 34

Slide 34 text

Repo remotes $ git remote add mirror https://mymirror.com/go-copy.git mirror https://mymirror.com/go-copy.git (fetch) mirror https://mymirror.com/go-copy.git (push) origin [email protected]:slok/go-copy.git (fetch) origin [email protected]:slok/go-copy.git (push) $ git remote -v origin [email protected]:slok/go-copy.git (fetch) origin [email protected]:slok/go-copy.git (push) $ git remote -v

Slide 35

Slide 35 text

$ git push origin master origin :devel

Slide 36

Slide 36 text

$ git fetch origin

Slide 37

Slide 37 text

$ git pull origin master

Slide 38

Slide 38 text

Workflow Working directory Repository Commit n Working directory Repository Commit n+1 Working directory Repository Commit n+2 Working directory Remote repo Push

Slide 39

Slide 39 text

Pointers

Slide 40

Slide 40 text

Position C1 C2 C3 C5 C4 C6 C7 master HEAD dev

Slide 41

Slide 41 text

Undo

Slide 42

Slide 42 text

$ git reset --hard HEAD^^ 56e05fced Before Pushing changes

Slide 43

Slide 43 text

$ git revert ef313dd --no-commit HEAD

Slide 44

Slide 44 text

Git Revert 5f201b3 Updated readme 58e5b57 Implemented creation of dirs in the file service $ git log -n2 --oneline d19f591 Revert "Updated readme" 5f201b3 Updated readme 58e5b57 Implemented creation of dirs in the file service $ git log -n3 --oneline [master d19f591] Revert "Updated readme" 1 file changed, 1 insertion(+), 1 deletion(-) $ git revert 5f201b3

Slide 45

Slide 45 text

$ git checkout -- 56e05fced 56e05fced http://git-scm.com/2011/07/11/reset.html

Slide 46

Slide 46 text

Checkout vs Reset C1 C2 C3 C5 master HEAD C1 C2 C3 C5 master HEAD $ git checkout master~2 $ git reset HEAD~2

Slide 47

Slide 47 text

Branches

Slide 48

Slide 48 text

$ git branch devel -d devel

Slide 49

Slide 49 text

$ git checkout -b devel devel -b devel origin/devel -t origin/devel

Slide 50

Slide 50 text

Branches * devel master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch -a Switched to a new branch 'devel' $ git checkout -b devel

Slide 51

Slide 51 text

Merges

Slide 52

Slide 52 text

$ git merge devel --no-commit devel devel -m “My awesome merge”

Slide 53

Slide 53 text

Fast forward merge C1 C2 C3 C5 master dev C1 C2 C3 C5 master dev Updating 817e279..48cdf3a Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) $ git merge dev

Slide 54

Slide 54 text

Conflicts $ git add ./file4.txt Auto-merging file4.txt CONFLICT (content): Merge conflict in file4.txt Automatic merge failed; fix conflicts and then commit the result. $ git merge dev <<<<<<< HEAD Oh! I'm the only developer here ======= No... You are not alone and this will conflict >>>>>>> dev $ cat ./file4.txt [master 1e90c43] Merge branch 'dev' $ git commit

Slide 55

Slide 55 text

Tags

Slide 56

Slide 56 text

$ git tag -a v1.0 -m "Version 1.0" -a v0.1 f539ca3 -m "Version 0.1" -d f539ca3

Slide 57

Slide 57 text

Remote tags Counting objects: 2, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 311 bytes, done. Total 2 (delta 0), reused 0 (delta 0) To [email protected]:slok/basic-git.git * [new tag] v0.1 -> v0.1 * [new tag] v1.0 -> v1.0 $ git push --tags origin

Slide 58

Slide 58 text

Stash

Slide 59

Slide 59 text

$ git stash list apply stash@{0} pop drop stash@{3}

Slide 60

Slide 60 text

$ git stash Saved working directory and index state WIP on master: 34f7998 #31 Add implementation to mark notifications as read or unread HEAD is now at 34f7998 #31 Add implementation to mark notifications as read or unread $ git stash # On branch master # Your branch is ahead of 'origin/master' by 3 commits. # # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: dwarf/notifications/urls.py # modified: dwarf/notifications/views.py # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (4cdbd16404fc6e8e378a669df2f168afa71ff1a5) $ git stash pop

Slide 61

Slide 61 text

Alias

Slide 62

Slide 62 text

$ git config --global alias.st status --global alias.ci commit

Slide 63

Slide 63 text

Rebase

Slide 64

Slide 64 text

$ git rebase devel Never rebase a public branch!

Slide 65

Slide 65 text

Rebase step 1 * 17d7264 (master) added notifications index template | * d9d7f36 (HEAD, testing) add more urls for notifications | * b2b673a add urls for notification |/ $ git log --graph -n 3 --oneline --all --decorate First, rewinding head to replay your work on top of it... Applying: add urls for notification Applying: add more urls for notifications $ git rebase master * 893eaef (HEAD, testing) add more urls for notifications * bd886fb add urls for notification * 17d7264 (master) added notifications index template $ git log --graph -n 3 --oneline --all --decorate

Slide 66

Slide 66 text

Rebase step 1 * 17d7264 (master) added notifications index template | * d9d7f36 (HEAD, testing) add more urls for notifications | * b2b673a add urls for notification |/ $ git log --graph -n 3 --oneline --all --decorate First, rewinding head to replay your work on top of it... Applying: add urls for notification Applying: add more urls for notifications $ git rebase master * 893eaef (HEAD, testing) add more urls for notifications * bd886fb add urls for notification * 17d7264 (master) added notifications index template $ git log --graph -n 3 --oneline --all --decorate WTF?!

Slide 67

Slide 67 text

Rebase step 2 * 893eaef (HEAD, testing, master) add more urls for notifications * bd886fb add urls for notification * 17d7264 added notifications index template $ git log --graph -n 3 --oneline --all --decorate Switched to branch 'master' Your branch is ahead of 'origin/master' by 4 commits. $ git checkout master Updating 17d7264..893eaef Fast-forward dwarf/notifications/views.py | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) $ git merge testing http://www.youtube.com/watch?v=cSf8cO0WB4o

Slide 68

Slide 68 text

Merge vs Rebase (Initial) C1 C2 C4 C3 C5 master dev

Slide 69

Slide 69 text

Merge vs Rebase (Merge) C1 C2 C4 C3 C5 master dev C6

Slide 70

Slide 70 text

Merge vs Rebase (Rebase) C1 C2 C4 C3 C5 master dev

Slide 71

Slide 71 text

Thank you

Slide 72

Slide 72 text

Questions

Slide 73

Slide 73 text

Kudos

Slide 74

Slide 74 text

Icons: Entypo Typography: Google web fonts OS Logos: http://commons.wikimedia.org Github: https://github.com Google docs: https://docs.google.com Git: http://git-scm.com Progit: http://git-scm.com/book

Slide 75

Slide 75 text

Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) http://xlarrakoetxea.org