Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git: the stupid content tracker

Git: the stupid content tracker

This talk is about explaining the basic concepts about git first, and then about explaining more advanced techniques and commands for using git on a daily basis, such as handling remote repositories, branches and tags, as well as explaining some advanced git commands.

It was written having in mind people who already know something about other non-distributed VCS’s (CVS, Subversion), but willing to switch to git at some point.

I informally delivered this talk in 2013, September the 11th, to a bunch of friends and colleagues who were interested in knowing more about git, how to use it and what things they could do with it.

To create these slides, I based them in the ones from the talk I delivered back in July 2010, for the GUADEC-ES conference (already in English, see [1]) and the extended version of it I delivered for the ”Xornadas Libres GPUL″ in March 2011 (still in Spanish, see [2]), this time doing it in English right from the start.

So, in a nutshell, you can see this talk as the accumulative result of my previous two talks about git, reviewed once again and translated to English. Hope you enjoy them.

[1] https://speakerdeck.com/mariospr/git-it-done-introduction-to-version-control-with-git
[2] https://speakerdeck.com/mariospr/control-de-versiones-con-git-mas-alla-del-commit-spanish

Mario Sánchez Prada

September 11, 2013
Tweet

More Decks by Mario Sánchez Prada

Other Decks in Technology

Transcript

  1. “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
  2. 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
  3. 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
  4. 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
  5. The problem Handling changes in a file, a project... Mario

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

    0: Do nothing (unique version) Mario Sanchez Prada Git: The stupid content tracker
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. Typical workflow with git Repository HEAD HEAD~1 ... HEAD~2 Index

    working tree Mario Sanchez Prada Git: The stupid content tracker
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. Typical workflow with git Index Repository working tree HEAD HEAD~1

    HEAD~2 ... HEAD~3 Mario Sanchez Prada Git: The stupid content tracker
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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 <commitID>: Visualizes details and content for commit commitID git log: Shows the full log from HEAD Mario Sanchez Prada Git: The stupid content tracker
  30. 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 <commitID>: Visualizes details and content for commit commitID git log: Shows the full log from HEAD Mario Sanchez Prada Git: The stupid content tracker
  31. 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
  32. 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
  33. 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
  34. 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 <[email protected]> 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
  35. Typical workflow with git - a specific example $ git

    log # Show history up-to-date commit 614c4e224284e2719fe040b64685b790606000a6 Author: Mario Sanchez Prada <[email protected]> Date: Mon May 3 09:31:19 2013 +0200 My first patch :-) commit fa16ae4ff64b3b968ca8991c90f123e62a6a009c Author: Mario Sanchez Prada <[email protected]> Date: Mon May 3 09:30:11 2013 +0200 Initial commit Mario Sanchez Prada Git: The stupid content tracker
  36. Typical workflow with git: commands Other helpful commands: git rm

    <file>: Removes file and get the Index ready with the changes for the next commit. git mv <fileA> <fileB>: Renames fileA as fileB and get the Index ready with the changes. git status: Shows the status of Working Tree and Index git clone <URL>: 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
  37. 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 <file>..." to update what will be committed) # (use "git checkout -- <file>..." 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 <file>..." to unstage) # # modified: A # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: C # Mario Sanchez Prada Git: The stupid content tracker
  38. Typical workflow with git: commands: git show <<< RIGHT AFTER

    COMMITING CHANGES WITH ’git commit’ >>> $ git show commit 614c4e224284e2719fe040b64685b790606000a6 Author: Mario Sanchez Prada <[email protected]> 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
  39. 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
  40. 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 <file> and git commit) git clone <URL>: 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 <name> <URL> git clone <URL> automatically creates one: origin Mario Sanchez Prada Git: The stupid content tracker
  41. 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
  42. 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
  43. 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
  44. 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
  45. 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
  46. Branches in git Create a new branch: git branch <branch-name>

    [<start-point>] Delete a branch: git branch (-d | -D) <branch-name> Rename a branch: git branch -m <old-name> <new-name> List the current branches: git branch [ -r | -a ] “Move” into a branch (check it out): git checkout [-b] <branch-name> Mario Sanchez Prada Git: The stupid content tracker
  47. 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
  48. 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
  49. 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
  50. 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
  51. 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
  52. 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
  53. 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
  54. 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
  55. 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
  56. 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
  57. 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
  58. 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
  59. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  60. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  61. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  62. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  63. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  64. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  65. Updating branches - git merge Updating a public branch: git

    merge <branch> 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
  66. Updating branches - git rebase Update a private branch: git

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

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

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

    rebase <new-base> 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
  70. Updating branches - git rebase Update a private branch: git

    rebase <new-base> 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
  71. 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
  72. Tags Just a alias for a specific commit that never

    changes Create a tag about the current commit (HEAD): git tag [-a|-s] <tag-name> Delete a tag by name: git tag -d <tag-name> List all tags: git tag -l Send a local tag to a remote repository: git push <repo-name> <tag-name> Send all local tags to a remote repository: git push --tags [repo-name] Mario Sanchez Prada Git: The stupid content tracker
  73. 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-name> Tag objects: Annotated tags: git tag -a <tag-name> Signed tags: git tag -s <tag-name> Mario Sanchez Prada Git: The stupid content tracker
  74. 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 <[email protected]> Date: Sun Mar 27 18:08:58 2011 +0200 Testing fix xyz commit bdd27c0e37a91c2ede4793d2a56407e7dd787f8b Author: Mario Sanchez Prada <[email protected]> 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
  75. 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
  76. 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
  77. 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
  78. 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 <filepath> Revert a commit (creates a new commit on top of HEAD): git revert <commitID> Modify the HEAD, the Index and the Working Tree: git reset [ --soft | --hard ] <commitID> Mario Sanchez Prada Git: The stupid content tracker
  79. Interesting commands Commit “surgery” Find commits in the current branch

    which have not been integrated yet in another branch: git cherry <integration-branch> Copy a specific commit on top of HEAD: git cherry-pick <commitID> Rewrite the history of commits, manually: git rebase -i <commitID> git commit --amend Rewrite the history of commits, automatically: git filter-branch <params> Binary search of commits: git bisect <start> | <good> | <bad> Check the history of git operations: git reflog Mario Sanchez Prada Git: The stupid content tracker
  80. Interesting commands Create, apply and send patches Create a diff

    file from a base commit: git diff <base-commitID> Apply a diff file (does not create a commit): git apply <diff-file> Create a set of “complete” patches from a base commit: git format-patch <base-commitID> Apply a set of “complete” patches, keeping all the meta: git am <patchfiles> Send patches by email: git send-email <email-address> Mario Sanchez Prada Git: The stupid content tracker
  81. 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