Slide 1

Slide 1 text

Git The stupid content tracker Mario Sánchez Prada [email protected] 2013 September 11th

Slide 2

Slide 2 text

“I think Git overshadows any other achievement that Linus guy ever had. He should stop working on that hobby kernel, and put more time into Git, I think it has potential.” Eitan Isaacson Open Source developer October 21st, 2009 Mario Sanchez Prada Git: The stupid content tracker

Slide 3

Slide 3 text

About me Computer Science Engineer by the University of Coruña Open Source developer (WebKit & GNOME & Maemo) Member of the GNOME and the WebKit communities Former member of the Open Source consultancy Igalia, now working in the AV team of Samsung Research UK Mario Sanchez Prada Git: The stupid content tracker

Slide 4

Slide 4 text

About me Computer Science Engineer by the University of Coruña Open Source developer (WebKit & GNOME & Maemo) Member of the GNOME and the WebKit communities Former member of the Open Source consultancy Igalia, now working in the AV team of Samsung Research UK git user since July 2008 Mario Sanchez Prada Git: The stupid content tracker

Slide 5

Slide 5 text

About git Distributed Version Control System (DVCS) Initially written in C by Linus Torvalds Replacement for BitKeeper in Linux kernel development Widely used nowadays, both for new and old projects http://git-scm.com Mario Sanchez Prada Git: The stupid content tracker

Slide 6

Slide 6 text

Basic concepts Mario Sanchez Prada Git: The stupid content tracker

Slide 7

Slide 7 text

The problem Handling changes in a file, a project... Mario Sanchez Prada Git: The stupid content tracker

Slide 8

Slide 8 text

The problem Handling changes in a file, a project... Option 0: Do nothing (unique version) Mario Sanchez Prada Git: The stupid content tracker

Slide 9

Slide 9 text

The problem Handling changes in a file, a project... Option 0: Do nothing (unique version) Option 1: Rudimentary system (manual copies) Project Project.bckp Project-20130514.bckp Project-20130514.bckp2 Project-20130514.bckp2-final Project-20130514.bckp2-last Project-20130514.bckp2-last-final Project-???????? Mario Sanchez Prada Git: The stupid content tracker

Slide 10

Slide 10 text

The problem Handling changes in a file, a project... Option 0: Do nothing (unique version) Option 1: Rudimentary system (manual copies) Project Project.bckp Project-20130514.bckp Project-20130514.bckp2 Project-20130514.bckp2-final Project-20130514.bckp2-last Project-20130514.bckp2-last-final Project-???????? Option 2: “Traditional” VCS’s: CVS, Subversion... They normally require a connection to a central repository Mario Sanchez Prada Git: The stupid content tracker

Slide 11

Slide 11 text

The problem Handling changes in a file, a project... Option 0: Do nothing (unique version) Option 1: Rudimentary system (manual copies) Project Project.bckp Project-20130514.bckp Project-20130514.bckp2 Project-20130514.bckp2-final Project-20130514.bckp2-last Project-20130514.bckp2-last-final Project-???????? Option 2: “Traditional” VCS’s: CVS, Subversion... They normally require a connection to a central repository Option 3: DVCS’s: Bazaar, Mercurial, Monotone, git... Total autonomy and flexibility (i.e. local commits) Mario Sanchez Prada Git: The stupid content tracker

Slide 12

Slide 12 text

VCS vs DVCS VCS Repository work station ... work station work station update com m it commit com m it server side client side central repository? Repository push / pull push / pull push / pull commit commit DVCS Repository commit Repository Mario Sanchez Prada Git: The stupid content tracker

Slide 13

Slide 13 text

VCS vs DVCS VCS Repository work station ... work station work station update com m it commit com m it server side client side central repository? Repository push / pull push / pull commit DVCS Repository commit Repository Mario Sanchez Prada Git: The stupid content tracker

Slide 14

Slide 14 text

VCS vs DVCS VCS Repository work station ... work station work station update com m it commit com m it server side client side central repository? Repository push / pull push / pull push / pull commit commit DVCS Repository commit Repository Mario Sanchez Prada Git: The stupid content tracker

Slide 15

Slide 15 text

Advantages and disadvantages of DVCS Advantages Full repository in the local machine: full history, branches, work offline... Improves the workflow for collaborative work Integration of changes from external sources Makes handling different versions for a project easier Better separation between private and public work Implicit back-up copies Enables working offline Disadvantages More complex than VCS’s. Harder learning curve Initially cloning is slower (not just the last commit) Full clones can require more hard disk space Mario Sanchez Prada Git: The stupid content tracker

Slide 16

Slide 16 text

Subversion (VCS) vs Git (DVCS) Subversion svn commit working tree Repository svn update client side server side Requires the two client / server parts to work Git another machine git push git pull Remote repository git commit -a working tree Repository git checkout Index git add git com m it local machine Doesn't require anything else but the local machine itself Mario Sanchez Prada Git: The stupid content tracker

Slide 17

Slide 17 text

Subversion (VCS) vs Git (DVCS) Subversion svn commit working tree Repository svn update client side server side Requires the two client / server parts to work Git git commit -a working tree another machine git push git pull Remote repository Repository git checkout Index git add git com m it local machine Mario Sanchez Prada Git: The stupid content tracker

Slide 18

Slide 18 text

Typical workflow with git Repository HEAD HEAD~1 ... HEAD~2 Index working tree Mario Sanchez Prada Git: The stupid content tracker

Slide 19

Slide 19 text

Typical workflow with git Repository HEAD HEAD~1 ... HEAD~2 git diff HEAD NO CHANGES Index git diff working tree NO CHANGES git diff --cached NO CHANGES Mario Sanchez Prada Git: The stupid content tracker

Slide 20

Slide 20 text

Typical workflow with git Repository HEAD HEAD~1 ... HEAD~2 git diff HEAD CHANGES Index git diff working tree CHANGES git diff --cached NO CHANGES Mario Sanchez Prada Git: The stupid content tracker

Slide 21

Slide 21 text

Typical workflow with git Index git add working tree Repository HEAD HEAD~1 ... HEAD~2 Add changes to the Index (prepare commit) Mario Sanchez Prada Git: The stupid content tracker

Slide 22

Slide 22 text

Typical workflow with git Repository HEAD HEAD~1 ... HEAD~2 git diff HEAD CHANGES Index git diff working tree CHANGES git diff --cached NO CHANGES Mario Sanchez Prada Git: The stupid content tracker

Slide 23

Slide 23 text

Typical workflow with git Repository Index working tree git com m it NEW HEAD HEAD HEAD~1 HEAD~2 ... Mario Sanchez Prada Git: The stupid content tracker

Slide 24

Slide 24 text

Typical workflow with git Index Repository working tree HEAD HEAD~1 HEAD~2 ... HEAD~3 Mario Sanchez Prada Git: The stupid content tracker

Slide 25

Slide 25 text

Typical workflow with git Index git diff NO CHANGES Repository git diff HEAD working tree HEAD HEAD~1 HEAD~2 ... HEAD~3 NO CHANGES git diff --cached NO CHANGES Mario Sanchez Prada Git: The stupid content tracker

Slide 26

Slide 26 text

Typical workflow with git Index Repository working tree HEAD HEAD~1 HEAD~2 ... HEAD~3 Repository HEAD HEAD~1 ... HEAD~2 Index working tree BEFORE AFTER Mario Sanchez Prada Git: The stupid content tracker

Slide 27

Slide 27 text

Typical workflow with git - git push Index Remote repository HEAD HEAD~1 ... HEAD~2 Repository working tree HEAD HEAD~1 HEAD~2 ... HEAD~3 Mario Sanchez Prada Git: The stupid content tracker

Slide 28

Slide 28 text

Typical workflow with git - git push Index Remote repository HEAD HEAD~1 ... HEAD~2 Repository working tree HEAD HEAD~1 HEAD~2 ... HEAD~3 Remote repository Repository Index working tree HEAD HEAD~1 HEAD~2 ... HEAD~3 HEAD~1 HEAD~2 ... HEAD~3 HEAD git push Mario Sanchez Prada Git: The stupid content tracker

Slide 29

Slide 29 text

Typical workflow with git - git pull HEAD HEAD~1 ... HEAD~2 Remote repository Repository HEAD HEAD~1 HEAD~2 ... HEAD~3 Index working tree Mario Sanchez Prada Git: The stupid content tracker

Slide 30

Slide 30 text

Typical workflow with git - git pull HEAD HEAD~1 ... HEAD~2 Remote repository Repository HEAD HEAD~1 HEAD~2 ... HEAD~3 Index working tree Remote repository Repository HEAD HEAD~1 HEAD~2 ... HEAD~3 HEAD~1 HEAD~2 ... HEAD~3 HEAD git pull Index working tree Mario Sanchez Prada Git: The stupid content tracker

Slide 31

Slide 31 text

Typical workflow with git: commands Basic commands: git init: Initializes the repository to work with git git add: Adds changes in the Working Tree to theIndex git commit: Makes changes in the Index permanent, creating a new commit and updating the HEAD. git diff: Differences between Working Tree and Index git show : Visualizes details and content for commit commitID git log: Shows the full log from HEAD Mario Sanchez Prada Git: The stupid content tracker

Slide 32

Slide 32 text

Typical workflow with git: commands Basic commands (extended version): git init: Initializes the repository to work with git git add: Adds changes in the Working Tree to theIndex git add -u: Adds all the changes to the Index git add --patch: Interactively asks which changes should go to the Index (hunk by hunk) git commit: Makes changes in the Index permanent, creating a new commit and updating the HEAD. git commit -a: git add -u && git commit git diff: Differences between Working Tree and Index git diff HEAD: Diff between Working Tree and HEAD git diff --cached: Diff between Index and HEAD git show : Visualizes details and content for commit commitID git log: Shows the full log from HEAD Mario Sanchez Prada Git: The stupid content tracker

Slide 33

Slide 33 text

Typical workflow with git - a specific example $ mkdir /tmp/git $ cd /tmp/git $ git init . # Initialize repository Initialized empty Git repository in /tmp/git/.git/ $ touch A B C $ git add A B C # Add new files to Index $ git commit -m "Initial commit" # First commit! [master (root-commit) fa16ae4] Initial commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 A create mode 100644 B create mode 100644 C Mario Sanchez Prada Git: The stupid content tracker

Slide 34

Slide 34 text

Typical workflow with git - a specific example $ git diff --stat # Working Tree <-> Index $ git diff --stat HEAD # Working Tree <-> HEAD $ git diff --stat --cached # Index <-> HEAD <<< MAKE SOME CHANGES IN THE WORKING TREE >>> $ git diff --stat # Working Tree <-> Index A | 3 +++ C | 3 +++ 2 files changed, 3 insertions(+), 0 deletions(-) $ git diff --stat HEAD # Working Tree <-> HEAD A | 3 +++ C | 3 +++ 2 files changed, 3 insertions(+), 0 deletions(-) $ git diff --stat --cached # Index <-> HEAD Mario Sanchez Prada Git: The stupid content tracker

Slide 35

Slide 35 text

Typical workflow with git - a specific example $ git add A C # Move changes to Index $ git diff --stat # Working Tree <-> Index $ git diff --stat HEAD # Working Tree <-> HEAD A | 3 +++ C | 3 +++ 2 files changed, 3 insertions(+), 0 deletions(-) $ git diff --stat --cached # Index <-> HEAD A | 3 +++ C | 3 +++ 2 files changed, 3 insertions(+), 0 deletions(-) Mario Sanchez Prada Git: The stupid content tracker

Slide 36

Slide 36 text

Typical workflow with git - a specific example $ git commit -m "My first patch :-)" # Commit changes [master 614c4e2] My first patch :-) 2 files changed, 3 insertions(+), 0 deletions(-) $ git diff --stat # Working Tree <-> Index $ git diff --stat HEAD # Working Tree <-> HEAD $ git diff --stat --cached # Index <-> HEAD $ git show --stat HEAD # Show last commit’s stats commit 614c4e224284e2719fe040b64685b790606000a6 Author: Mario Sanchez Prada Date: Mon May 3 09:31:19 2013 +0200 My first patch :-) A | 3 +++ C | 3 +++ 2 files changed, 3 insertions(+), 0 deletions(-) Mario Sanchez Prada Git: The stupid content tracker

Slide 37

Slide 37 text

Typical workflow with git - a specific example $ git log # Show history up-to-date commit 614c4e224284e2719fe040b64685b790606000a6 Author: Mario Sanchez Prada Date: Mon May 3 09:31:19 2013 +0200 My first patch :-) commit fa16ae4ff64b3b968ca8991c90f123e62a6a009c Author: Mario Sanchez Prada Date: Mon May 3 09:30:11 2013 +0200 Initial commit Mario Sanchez Prada Git: The stupid content tracker

Slide 38

Slide 38 text

Typical workflow with git: commands Other helpful commands: git rm : Removes file and get the Index ready with the changes for the next commit. git mv : Renames fileA as fileB and get the Index ready with the changes. git status: Shows the status of Working Tree and Index git clone : Clones a remote repository git push: Sends local commits to a remote repository git pull: Brings commits from a remote repository Mario Sanchez Prada Git: The stupid content tracker

Slide 39

Slide 39 text

Typical workflow with git: commands: git status <<< RIGHT BEFORE ADDING A AND C TO INDEX WITH ’git add A C’ >>> $ git status # On branch master # Changed but not updated: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: A # modified: C # no changes added to commit (use "git add" and/or "git commit -a") $ git add A $ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: A # # Changed but not updated: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: C # Mario Sanchez Prada Git: The stupid content tracker

Slide 40

Slide 40 text

Typical workflow with git: commands: git show <<< RIGHT AFTER COMMITING CHANGES WITH ’git commit’ >>> $ git show commit 614c4e224284e2719fe040b64685b790606000a6 Author: Mario Sanchez Prada Date: Mon May 3 09:31:19 2013 +0200 My first patch :-) diff --git a/A b/A index e69de29..1802a74 100644 --- a/A +++ b/A @@ -0,0 +1,3 @@ +aaa +bbb +ccc diff --git a/C b/C index e69de29..1802a74 100644 --- a/C +++ b/C @@ -0,0 +1,3 @@ +aaa +bbb +ccc Mario Sanchez Prada Git: The stupid content tracker

Slide 41

Slide 41 text

Comparing commands: Subversion - Git Subversion Git svnadmin create repo git init svn import filepath git add filepath git commit svn checkout URL git clone URL svn add|rm|mv file git add|rm|mv file svn diff git diff svn commit git commit -a git push svn update git pull svn status git status svn log git log svn blame file git blame file Mario Sanchez Prada Git: The stupid content tracker

Slide 42

Slide 42 text

Repositories and branches Mario Sanchez Prada Git: The stupid content tracker

Slide 43

Slide 43 text

Local and remote repositories Two types of repositories: Local repository: Local working directory under version control with git (it contains a .git/ directory) They can be “created” by either: git init: Initializes the current directory to be used with git (needed to git add and git commit) git clone : Clones a remote repository in a local directory, stablishing a link to the original one, throughout the remote repository origin. Remote repositories: Any non-local repository where we have cloned our local working directory from Can be linked with git remote add git clone automatically creates one: origin Mario Sanchez Prada Git: The stupid content tracker

Slide 44

Slide 44 text

What’s a branch? A branch is a paralell line of work which allow us to make and try out certain changes from a given point on, without altering the original line of work it was created from. Mario Sanchez Prada Git: The stupid content tracker

Slide 45

Slide 45 text

What’s a branch? A branch is a paralell line of work which allow us to make and try out certain changes from a given point on, without altering the original line of work it was created from. Once the changes done in the branch have been proved to work well, they can be integrated in the original branch, resolving the “conflicts” that could have appeared since its creation. Mario Sanchez Prada Git: The stupid content tracker

Slide 46

Slide 46 text

What’s a branch? A branch is a paralell line of work which allow us to make and try out certain changes from a given point on, without altering the original line of work it was created from. Once the changes done in the branch have been proved to work well, they can be integrated in the original branch, resolving the “conflicts” that could have appeared since its creation. Implementation: With other VCS’s (Subversion): Separate directories With git: An alias to the commit that will be the HEAD for that branch (almost-zero cost, really fast). Thus, that alias will get updated every time a new commit is added. Mario Sanchez Prada Git: The stupid content tracker

Slide 47

Slide 47 text

What’s a branch? - Subversion vs Git branch-1 branch-2 trunk (master branch) Subversion ... svn copy svn merge svn copy svn merge Mario Sanchez Prada Git: The stupid content tracker

Slide 48

Slide 48 text

What’s a branch? - Subversion vs Git branch-1 branch-2 trunk (master branch) Subversion ... svn copy svn merge svn copy svn merge master branch-2 branch-1 Git ... git branch git branch git merge git merge Mario Sanchez Prada Git: The stupid content tracker

Slide 49

Slide 49 text

Branches in git Create a new branch: git branch [] Delete a branch: git branch (-d | -D) Rename a branch: git branch -m List the current branches: git branch [ -r | -a ] “Move” into a branch (check it out): git checkout [-b] Mario Sanchez Prada Git: The stupid content tracker

Slide 50

Slide 50 text

Branches in git - an example $ git branch * master $ git branch mybranch-1 $ git branch mybranch-2 $ git branch * master mybranch-1 mybranch-2 $ git checkout mybranch-1 Switched to branch ’mybranch-1’ $ git branch master * mybranch-1 mybranch-2 Mario Sanchez Prada Git: The stupid content tracker

Slide 51

Slide 51 text

Branches in git - an example $ git branch -m mybranch-1 branch-1 $ git branch -m mybranch-2 branch-2 $ git branch master * branch-1 branch-2 $ git checkout master Switched to branch ’master’ $ git branch -d branch-1 Deleted branch branch-1 (was 59f1309). $ git branch -d branch-2 Deleted branch branch-2 (was e721bce). $ git branch * master Mario Sanchez Prada Git: The stupid content tracker

Slide 52

Slide 52 text

Why using branches? They are fast, convenient, and really “cheap” To try an idea out (experiment) Separate public and private work One branch per bug/feature Prepare for a new release (integration) As a temporary backup (snapshot) It’s the usual way of working with git Mario Sanchez Prada Git: The stupid content tracker

Slide 53

Slide 53 text

Local and remote branches Two types of branches: Local branches: Branches created in the local machine to work on top of them, making all the needed changes. Remote branches: Branches from a remote repository that we can link to local branches to work with them. Clarifications: Both the local and the remote branches are always in our local repository (local/remote concept depends on the POV). The remote branches act as a cache of non-local branches in remote repositories (they are rsync-ed). The local branches are pushed/pulled to/from the remote repositories throughout their associated remote branches. Mario Sanchez Prada Git: The stupid content tracker

Slide 54

Slide 54 text

An example of repositories and branches: epiphany Local branches $ git branch 136292 539716 602547 608980 * 611400 alex master Using branches in this example: One branch per bug One experimental branch (alex) One “main” branch (master). Remote branches $ git remote origin $ git branch -r origin/HEAD -> origin/master origin/Release043 origin/bookmarks-toolbars-changes origin/bookmarksbar-separation origin/css-fonts-branch origin/eog-menu-api origin/gnome-2-10 [...] origin/master origin/mozilla-embed-strings origin/new-completion origin/new-downloader origin/pre-gnome-2-10 origin/pre-gnome-2-14 origin/pre-gnome-2-6 origin/pre-gnome-2-8 origin/release-1-2-1 origin/webcore-branch origin/webkit origin/xulrunner Mario Sanchez Prada Git: The stupid content tracker

Slide 55

Slide 55 text

Local and remote branches - a specific example List remote branches and track them locally $ git branch -a # List ALL branches (local/remote) * master remotes/origin/master remotes/origin/other-branch $ git branch private # Create new private branch $ git branch other-branch origin/other-branch Branch other-branch set up to track remote branch other-branch from origin. $ git branch -a # List ALL branches * master private other-branch remotes/origin/master remotes/origin/other-branch Mario Sanchez Prada Git: The stupid content tracker

Slide 56

Slide 56 text

Local and remote branches - a specific example Rename and remove branches $ git branch -m private private-work $ git branch -m otherbranch other-branch $ git branch master * private-work other-branch $ git checkout master Switched to branch ’master’ $ git branch -d private-work other-branch Deleted branch private-work (was 59f1309). Deleted branch other-branch (was e721bce). $ git branch * master Mario Sanchez Prada Git: The stupid content tracker

Slide 57

Slide 57 text

Local and remote branches - a specific example Send changes in local branches to a remote repository <<< MAKE SOME CHANGES IN THE WORKING TREE >>> $ git commit -a -m "Last commit" [master 70f7c77] Last commit 1 files changed, 1 insertions(+), 0 deletions(-) $ git push Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 272 bytes, done. Total 3 (delta 1), reused 0 (delta 0) To ssh://[email protected]/var/git/myrepo.git 855a39b..70f7c77 master -> master Mario Sanchez Prada Git: The stupid content tracker

Slide 58

Slide 58 text

Local and remote branches - a specific example Pull changes from a remote repository into a local branch <<< WORKING TREE IS CLEAN (No changes) >>> $ git pull Updating 43f7dbc..70f7c77 Fast-forward body.tex | 10 +++++++++- closing.tex | 8 ++++++++ cover.tex | 8 ++++++++ opening.tex | 41 ++++++++++++------------- toc.tex | 8 ++++++++ 7 files changed, 45 insertions(+), 30 deletions(-) Mario Sanchez Prada Git: The stupid content tracker

Slide 59

Slide 59 text

Updating the branches Two typical situations: Add changes in a private branch to a public branch (integrate local changes) Modify a private branch with new code from a public branch where it was created from (update) Mario Sanchez Prada Git: The stupid content tracker

Slide 60

Slide 60 text

Updating the branches Two typical situations: Add changes in a private branch to a public branch (integrate local changes) We can’t alter past history in a public branch We need “clean” changes ready to be applied on top of HEAD in the public branch Modify a private branch with new code from a public branch where it was created from (update) Mario Sanchez Prada Git: The stupid content tracker

Slide 61

Slide 61 text

Updating the branches Two typical situations: Add changes in a private branch to a public branch (integrate local changes) We can’t alter past history in a public branch We need “clean” changes ready to be applied on top of HEAD in the public branch Modify a private branch with new code from a public branch where it was created from (update) We can alter past history in a private branch It’s more interesting to “change the past” whenever it’s needed in order to always have “clean changes” in the branch where it was created from (it could have changed) Mario Sanchez Prada Git: The stupid content tracker

Slide 62

Slide 62 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: There are changes in the public branch where the private one was created from: Mario Sanchez Prada Git: The stupid content tracker

Slide 63

Slide 63 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: master mybranch B A D C There are changes in the public branch where the private one was created from: Mario Sanchez Prada Git: The stupid content tracker

Slide 64

Slide 64 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: master mybranch B A D C There are changes in the public branch where the private one was created from: Mario Sanchez Prada Git: The stupid content tracker

Slide 65

Slide 65 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: C B A D master mybranch master mybranch B A D C There are changes in the public branch where the private one was created from: Mario Sanchez Prada Git: The stupid content tracker

Slide 66

Slide 66 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: C B A D master mybranch master mybranch B A D C There are changes in the public branch where the private one was created from: B A D C master mybranch Mario Sanchez Prada Git: The stupid content tracker

Slide 67

Slide 67 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: C B A D master mybranch master mybranch B A D C There are changes in the public branch where the private one was created from: E B A F D C master mybranch Mario Sanchez Prada Git: The stupid content tracker

Slide 68

Slide 68 text

Updating branches - git merge Updating a public branch: git merge There are no changes in the public branch where the private one was created from: C B A D master mybranch master mybranch B A D C There are changes in the public branch where the private one was created from: E B A F D C master mybranch master mybranch E B A F D C meta commit Mario Sanchez Prada Git: The stupid content tracker

Slide 69

Slide 69 text

Updating branches - git rebase Update a private branch: git rebase B A D C master mybranch Mario Sanchez Prada Git: The stupid content tracker

Slide 70

Slide 70 text

Updating branches - git rebase Update a private branch: git rebase E B A F D C master mybranch Mario Sanchez Prada Git: The stupid content tracker

Slide 71

Slide 71 text

Updating branches - git rebase Update a private branch: git rebase master mybranch E B A F D C E B A F D C master mybranch Mario Sanchez Prada Git: The stupid content tracker

Slide 72

Slide 72 text

Updating branches - git rebase Update a private branch: git rebase master mybranch E B A F D C E B A F D C master mybranch E B A F C* master mybranch C* = [E + F] + C Mario Sanchez Prada Git: The stupid content tracker

Slide 73

Slide 73 text

Updating branches - git rebase Update a private branch: git rebase master mybranch E B A F D C E B A F D C master mybranch E B A F D* C* master mybranch E B A F C* master mybranch C* = [E + F] + C D* = [E + F] + D C* = [E + F] + C Mario Sanchez Prada Git: The stupid content tracker

Slide 74

Slide 74 text

Updating branches One personal tip (whenever it’s possible) Before updating a public branch with git merge to do a git push later on, it’s a good idea to do a git rebase first from the private branch, in order to avoid getting a metacommit. $ git checkout mybranch # Change to private branch $ git rebase master # Rebase private branch $ git checkout master # Change back to master $ git merge mybranch # Merge changes from mybranch $ git push # Push to remote repository If git push fails because we are not up to date, just do: $ git pull --rebase This command pulls new commits from a remote branch first and then put our local changes on top, all in one single step. Mario Sanchez Prada Git: The stupid content tracker

Slide 75

Slide 75 text

Tags and references Mario Sanchez Prada Git: The stupid content tracker

Slide 76

Slide 76 text

Tags Just a alias for a specific commit that never changes Create a tag about the current commit (HEAD): git tag [-a|-s] Delete a tag by name: git tag -d List all tags: git tag -l Send a local tag to a remote repository: git push Send all local tags to a remote repository: git push --tags [repo-name] Mario Sanchez Prada Git: The stupid content tracker

Slide 77

Slide 77 text

Tags Why using tags? To mark new releases of a project To mark important milestones in the development process: bug fixes, development of major features... It’s a common practice when managing software projects Lightweight tags VS Tag objects Lightweight tags (alias): git tag Tag objects: Annotated tags: git tag -a Signed tags: git tag -s Mario Sanchez Prada Git: The stupid content tracker

Slide 78

Slide 78 text

Tags - a specific example $ git tag -a TESTING_FIX # Create new TAG $ git tag -l # List existing tags TESTING_FIX $ git show TESTING_FIX # Show details for the TAG tag TESTING_FIX Tagger: Mario Sanchez Prada Date: Sun Mar 27 18:08:58 2011 +0200 Testing fix xyz commit bdd27c0e37a91c2ede4793d2a56407e7dd787f8b Author: Mario Sanchez Prada Date: Sat Mar 26 13:11:35 2011 +0100 [...] $ git tag -d TESTING_FIX # Delete TAG Deleted tag ’TESTING_FIX’ (was a0418a0) Mario Sanchez Prada Git: The stupid content tracker

Slide 79

Slide 79 text

References References to specific commits: Current commit in the current branch: HEAD Hash id for “a random commit”: 3da14d804c3153c433d0435640bcdd06158b123e One branch: mybranch One tag: mytag Relative references Browsing history backwards (parent, grandparent...) Commit 1 position older: ref~1 o ref^ Commit 3 positions older: ref~3 o ref^^^ Browsing the list of parents (interesting for merges) First parent for the reference: ref^ Second parent for the reference: ref^2 N-th parent for the reference: ref^N Mario Sanchez Prada Git: The stupid content tracker

Slide 80

Slide 80 text

References WARNING! ACHTUNG! ATENCION! ATTENZIONE! REF~1 == REF^ (1st ancestor == parent) REF~2 == REF^^ (2nd ancestor == parent of parent) REF~2 != REF^2 (2nd ancestor != 2nd parent) master branch-1 HEAD HEAD^^ HEAD~2 HEAD^ HEAD~1 HEAD^^^ HEAD~3 HEAD^2 branch-2 HEAD^3 ... Mario Sanchez Prada Git: The stupid content tracker

Slide 81

Slide 81 text

Other things... Mario Sanchez Prada Git: The stupid content tracker

Slide 82

Slide 82 text

Interesting commands Management of the Working Tree and the Index Show the state of the Working Tree and the Index: git status Add all the changes to the Index: git add -u Interactively review which changes should go to the Index: git add --patch Differences between Working Tree and Index: git diff Diff between Working Tree and HEAD Diff between Index and HEAD: git diff --cached Save and restore state in the Working Tree and the Index: git stash & git stash pop Mario Sanchez Prada Git: The stupid content tracker

Slide 83

Slide 83 text

Interesting commands Management of commits Show the full commit log from HEAD (or commitID): git log [commitID] Visualize details and content for one commit: git show [commitID] Show authors for the latest changes made in one filepath: git blame Revert a commit (creates a new commit on top of HEAD): git revert Modify the HEAD, the Index and the Working Tree: git reset [ --soft | --hard ] Mario Sanchez Prada Git: The stupid content tracker

Slide 84

Slide 84 text

Interesting commands Commit “surgery” Find commits in the current branch which have not been integrated yet in another branch: git cherry Copy a specific commit on top of HEAD: git cherry-pick Rewrite the history of commits, manually: git rebase -i git commit --amend Rewrite the history of commits, automatically: git filter-branch Binary search of commits: git bisect | | Check the history of git operations: git reflog Mario Sanchez Prada Git: The stupid content tracker

Slide 85

Slide 85 text

Interesting commands Create, apply and send patches Create a diff file from a base commit: git diff Apply a diff file (does not create a commit): git apply Create a set of “complete” patches from a base commit: git format-patch Apply a set of “complete” patches, keeping all the meta: git am Send patches by email: git send-email Mario Sanchez Prada Git: The stupid content tracker

Slide 86

Slide 86 text

Where to go from here Git from the bottom up (Excellent tutorial): http://ftp.newartisans.com/pub/git.from. bottom.up.pdf Git User’s Manual: http://www.kernel.org/pub/software/scm/git/ docs/v1.7.1/user-manual.html Git tutorial manual page (man gittutorial): http://www.kernel.org/pub/software/scm/git/ docs/v1.7.1/gittutorial.html Everyday GIT With 20 Commands Or So: http://www.kernel.org/pub/software/scm/git/ docs/v1.7.1/everyday.html Gitorious: infrastructure for open source projects with Git: http://gitorious.org Mario Sanchez Prada Git: The stupid content tracker

Slide 87

Slide 87 text

Questions? Mario Sanchez Prada Git: The stupid content tracker

Slide 88

Slide 88 text

Thank you! Mario Sanchez Prada Git: The stupid content tracker