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

Git Workflows

Git Workflows

Radoslav Stankov

October 19, 2018
Tweet

More Decks by Radoslav Stankov

Other Decks in Technology

Transcript

  1. Radoslav Stankov 18/10/2018
    Improving Your
    Workflows

    View full-size slide

  2. Radoslav Stankov
    @rstankov

    blog.rstankov.com

    github.com/rstankov

    twitter.com/rstankov

    View full-size slide

  3. Git: Under the hooh

    View full-size slide

  4. refs/
    objects/
    logs/
    hooks/
    index
    HEAD
    config
    COMMIT_EDITMSG

    View full-size slide

  5. refs/
    objects/
    logs/
    hooks/
    index
    HEAD
    config
    COMMIT_EDITMSG

    View full-size slide

  6. "Git just object database
    + some shell scripts"

    View full-size slide

  7. Content
    Type + ' ' + Size + \0
    Content

    View full-size slide

  8. Content
    Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...

    View full-size slide

  9. Content
    Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...
    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f

    View full-size slide

  10. Content
    Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...
    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f

    View full-size slide

  11. Content
    Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...
    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f

    View full-size slide

  12. bbd51c
    bbd51c3fa
    bbd51c3fa6ccab
    bbd51c3fa6ccabc8e3bf95
    bbd51c3fa6ccabc8e3bf9559cd0af21558995d3f

    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f


    View full-size slide

  13. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  14. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide


  15. Blob

    export function toggleTopicFollow(topicId: number): Dispatchable {
    return function(dispatch: Dispatch, getState: Function, api: any): void {
    const { currentUser } = getState();
    if (isFollowingTopic(currentUser, id)) {
    api.topics.followers.delete({ topicId });
    dispatch({ type: UNFOLLOW_TOPIC, payload: { topicId } });
    } else {
    api.topics.followers.create({ topicId });
    dispatch({ type: FOLLOW_TOPIC, payload: { topicId } });
    }
    };
    }

    View full-size slide

  16. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide


  17. Tree

    client/
    server/
    README.md

    View full-size slide


  18. Tree

    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)

    View full-size slide

  19. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/

    Tree


    View full-size slide

  20. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/
    mode

    Tree


    View full-size slide

  21. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/

    Tree


    View full-size slide

  22. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/
    type

    Tree


    View full-size slide

  23. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/

    Tree


    View full-size slide

  24. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/
    ref

    Tree


    View full-size slide

  25. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/

    Tree


    View full-size slide

  26. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/
    name

    Tree


    View full-size slide

  27. Tree
    100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README.md
    040000 blob 8f94139338f9404f26296befa88755fc2598c289 client/
    040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 server/

    Tree


    View full-size slide

  28. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide


  29. Commit


    View full-size slide


  30. Commit

    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)

    View full-size slide


  31. Commit

    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)

    View full-size slide


  32. Commit

    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit

    View full-size slide


  33. Commit

    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Commit

    (parent)

    View full-size slide

  34. Commit
    Tree a906cb2a4a904a152e80877d4088654daad0c859
    Parent 8f94139338f9404f26296befa88755fc2598c289
    Author Radoslav Stankov 123242
    Date Sat May 5 18:09:34 2018 -0700

    Commit


    View full-size slide

  35. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  36. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  37. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  38. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  39. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  40. Content
    Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...
    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f

    View full-size slide

  41. Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...
    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f
    Commit
    Tree
    Blob

    View full-size slide

  42. Type + ' ' + Size + \0
    Content
    SHA1 digest

    bbd51c3fa6ccabc8e3bf955958...
    .git/objects/bb/d51c3fa6ccabc8e3bf9559cd0af21558995d3f
    Commit
    Tree
    Blob

    View full-size slide

  43. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  44. Commit
    Tree
    Blob

    Main Object Types


    View full-size slide

  45. refs/
    objects/
    logs/
    hooks/
    index
    HEAD
    config
    COMMIT_EDITMSG

    View full-size slide

  46. refs/
    objects/
    logs/
    hooks/
    index
    HEAD
    config
    COMMIT_EDITMSG

    View full-size slide

  47. "Refs are basically
    pointers to commit"

    View full-size slide

  48. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit

    View full-size slide

  49. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit

    View full-size slide

  50. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (mater)

    View full-size slide

  51. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)
    Ref

    (mater)

    View full-size slide

  52. Tag 

    (v1)
    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)
    Ref

    (mater)

    View full-size slide

  53. Tag 

    (v1)
    Ref

    (remote/master)
    Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)
    Ref

    (mater)

    View full-size slide

  54. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (mater)
    Tag 

    (v1)
    Ref

    (remote/master)
    Ref

    (HEAD)

    View full-size slide

  55. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)
    Ref

    (mater)

    View full-size slide

  56. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)

    View full-size slide

  57. Tree
    Blob
    (/README.md)
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)
    Commit
    Tree
    Blob
    (/README.md)

    View full-size slide

  58. Tree
    Tree
    (/client/)
    Tree
    (/server/)
    Commit
    Ref

    (HEAD)
    Commit
    Tree
    Blob
    (/README.md)
    Commit
    Tree

    View full-size slide

  59. git clone
    git add
    git commit
    git status
    git fetch
    git push
    git pull
    git checkout
    git branch
    git log

    git diff

    Main Git Commands


    View full-size slide


  60. Main Git Commands

    Remote
    Local
    Staging
    Unstaged

    View full-size slide


  61. Main Git Commands

    Remote
    Local
    Staging
    Unstaged
    git add

    View full-size slide


  62. Main Git Commands

    Remote
    Local
    Staging
    Unstaged
    git add
    git commit

    View full-size slide


  63. Main Git Commands

    Remote
    Local
    Staging
    Unstaged
    git add
    git commit
    git push

    View full-size slide


  64. Main Git Commands

    Remote
    Local
    Staging
    Unstaged
    git add
    git commit
    git push
    git pull

    View full-size slide


  65. Main Git Commands

    Remote
    Local
    Staging
    Unstaged
    git add
    git commit
    git push
    git pull
    git checkout

    View full-size slide

  66. refs/
    objects/
    logs/
    hooks/
    index
    HEAD
    config
    COMMIT_EDITMSG

    View full-size slide

  67. Merge Rebase

    View full-size slide

  68. Master Commit M1

    View full-size slide

  69. Master
    Commit M1
    Commit M2
    Commit M3

    View full-size slide

  70. Master Branch
    Commit M1
    Commit M2
    Commit M3

    View full-size slide

  71. Master
    Branch
    Commit M1
    Commit M2
    Commit M3
    Commit M4

    View full-size slide

  72. Master
    Branch
    Commit M1
    Commit M2
    Commit M3
    Commit M4
    Commit B1

    View full-size slide

  73. Master
    Branch
    Commit M1
    Commit M2
    Commit M3
    Commit M4
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    View full-size slide

  74. Master Branch
    Commit M1
    Commit M2
    Commit M3
    Commit M4
    Commit M5
    Commit M6
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    View full-size slide


  75. git merge [branch]

    Master
    Branch
    Commit M1
    Commit M2
    Commit M3
    Commit M4
    Commit M5
    Commit M6
    Merge Commit
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    View full-size slide

  76. Master Branch
    Commit M1
    Commit M2
    Commit M3
    Commit M4
    Commit M5
    Commit M6
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    git rebase master [branch]


    View full-size slide

  77. Branch
    Master
    Commit M1
    Commit M2
    Commit M3
    Commit M4
    Commit M5
    Commit M6
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    git rebase master [branch]


    View full-size slide

  78. Branch
    Master
    Commit M5
    Commit M6
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    git rebase master [branch]


    View full-size slide

  79. Branch
    Master
    Commit M5
    Commit M6
    Commit B1
    Commit B2
    Commit B3
    Commit B4

    git rebase master [branch]


    View full-size slide

  80. Branch
    Master
    Commit M5
    Commit M6
    Commit B1x
    Commit B2
    Commit B3
    Commit B4

    git rebase master [branch]


    View full-size slide

  81. Branch
    Master
    Commit M5
    Commit M6
    Commit B1x
    Commit B2x
    Commit B3x
    Commit B4x

    git rebase master [branch]


    View full-size slide

  82. Branch
    Master
    Commit M5
    Commit M6
    Commit B1x
    Commit B2x
    Commit B3x
    Commit B4x

    git merge [branch] 


    View full-size slide

  83. Improve your tools

    View full-size slide

  84. ~/.gitconfig

    View full-size slide

  85. [alias]
    st = status
    br = branch
    co = checkout

    https://github.com/RStankov/config_files/blob/master/dot/gitconfig


    View full-size slide

  86. [alias]
    stahs = stash
    puhs = push
    hsow = show

    https://github.com/RStankov/config_files/blob/master/dot/gitconfig


    View full-size slide

  87. [alias]
    stahs = stash
    puhs = push
    hsow = show

    https://github.com/RStankov/config_files/blob/master/dot/gitconfig

    "

    View full-size slide

  88. alias ga="git add -A"
    alias gp="git pull --rebase"
    alias grc="git add .; git rebase --continue"
    alias gr="git rebase -i"
    alias gs="git stash"
    alias gco="git checkout"
    alias gl="git lol"
    alias gd="git diff"
    alias gdc="git diff --cached"
    alias gst="git status"

    https://github.com/RStankov/config_files/blob/master/dot/zsh/aliases


    View full-size slide

  89. [alias]
    ls = ls-files
    undo = reset --soft HEAD^
    amend = commit --amend
    unstage = reset HEAD

    https://github.com/RStankov/config_files/blob/master/dot/gitconfig


    View full-size slide

  90. [alias]
    lol = log --graph --decorate --
    pretty='format:%C(yellow)%h%Cgreen%d%Creset
    %s %C(white) (%an, %ar)%Creset' --abbrev-
    commit
    today = log --stat --since='1 Day Ago' --
    graph --pretty=oneline --abbrev-commit --
    date=relative

    https://github.com/RStankov/config_files/blob/master/dot/gitconfig


    View full-size slide


  91. git lol


    View full-size slide


  92. git today


    View full-size slide

  93. ~/bin/git-***

    View full-size slide

  94. ~/bin/git-pull-request

    View full-size slide


  95. https://github.com/RStankov/config_files/blob/master/bin/git-pull-request

    #!/bin/bash
    current_branch=`git rev-parse --abbrev-ref HEAD`
    remote_url=`git remote get-url origin | awk '{gsub(/
    [email protected]:/,"")}1' | awk '{gsub(/\.git/,"")}1'`
    git push origin $current_branch --set-upstream
    open https://github.com/$remote_url/compare/$current_branch

    git pull-request


    View full-size slide

  96. ~/bin/rebase-on-master

    View full-size slide


  97. https://github.com/RStankov/config_files/blob/master/bin/git-rebase-on-master

    #!/bin/bash
    current_branch=`git rev-parse --abbrev-ref HEAD`
    git checkout master
    git pull origin master --rebase
    git rebase master $current_branch

    git rebase-on-master


    View full-size slide

  98. ~/bin/delete-merged

    View full-size slide


  99. https://github.com/RStankov/config_files/blob/master/bin/git-delete-merged

    #!/bin/bash
    current_branch=`git rev-parse --abbrev-ref HEAD`
    git checkout master
    git pull origin master --rebase
    git rebase master $current_branch

    git delete-merged


    View full-size slide


  100. Fork


    https://git-fork.com


    View full-size slide


  101. https://git-fork.com


    View full-size slide

  102. "I only use Git GUI to
    stage files to commits
    and amending previous
    commits"

    View full-size slide


  103. https://git-fork.com


    View full-size slide


  104. https://git-fork.com


    View full-size slide