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

Git: A Distributed Revision Control System

Git: A Distributed Revision Control System

Slides on Git: a distributed revision control system

Jaime Arias Almeida

December 15, 2018
Tweet

More Decks by Jaime Arias Almeida

Other Decks in Programming

Transcript

  1. Git: A Distributed Revision
    Control System (Part I)
    Presented by: Jaime Arias

    View full-size slide

  2. What is it?
    ▪ Git is a free and open source
    distributed version control
    system designed to handle
    everything from small to very
    large projects.
    2

    View full-size slide

  3. What is it?
    3
    * Pro Git book, written by Scott Chacon and Ben Straub and published by Apress

    View full-size slide

  4. 4
    Installation
    git --version
    sudo apt install git-all
    sudo dnf install git-all
    https://git-scm.com/download/mac
    https://gitforwindows.org/
    https://www.gitkraken.com

    View full-size slide

  5. 1
    Starter Kit
    Let’s start with git
    5

    View full-size slide

  6. Basic Configuration
    6
    git config --global user.name "Jaime Arias"
    git config --global user.email "[email protected]"
    git config --global core.editor vim

    View full-size slide

  7. Initializing a New Repository (Locally)
    7
    mkdir my-project && cd my-project
    git init .

    View full-size slide

  8. Creating a New Repository (Remotely)
    8
    https://depot.lipn.univ-paris13.fr/

    View full-size slide

  9. Creating a New Repository (Remotely)
    9
    https://depot.lipn.univ-paris13.fr/

    View full-size slide

  10. Cloning an Existing Repository
    10
    git clone
    [email protected]:arias/git-test.git
    cd git-test

    View full-size slide

  11. 2
    Working Locally
    Let’s create commits!
    11

    View full-size slide

  12. 12
    Working with the Repository
    * Pro Git book, written by Scott Chacon and Ben Straub and published by Apress

    View full-size slide

  13. Creating a New Commit
    ▪ A commit is created from the
    changes to one or more files on
    disk.
    ▪ Git allows files to be added
    incrementally to the stage area.
    13
    echo “print ‘hello world’” > test.py
    git status

    View full-size slide

  14. 14
    Working with the Repository
    add
    * Pro Git book, written by Scott Chacon and Ben Straub and published by Apress

    View full-size slide

  15. Creating a New Commit
    add
    15
    git add test.py
    git status

    View full-size slide

  16. 16
    Working with the Repository
    commit
    * Pro Git book, written by Scott Chacon and Ben Straub and published by Apress

    View full-size slide

  17. Creating a New Commit
    commit
    17
    git commit -m “add test.py file”
    git log

    View full-size slide

  18. 18
    Working with the Repository
    rm --cached
    * Pro Git book, written by Scott Chacon and Ben Straub and published by Apress

    View full-size slide

  19. Removing a File
    rm --cached
    19
    git rm --cached trash.py
    git status
    touch thrash.py
    git add trash.py && git status
    ▪ Removes the file from version
    control but preserves the file
    locally

    View full-size slide

  20. Ignoring Files
    .gitignore
    20
    echo trash.txt >> .gitignore
    git status
    touch .gitignore trash.txt
    git status
    ▪ A gitignore file specifies intentionally
    untracked files that Git should ignore.
    ▫ https://www.gitignore.io/

    View full-size slide

  21. LET’S REVIEW SOME COMMANDS
    git init
    Creates a new local
    repository.
    git add
    Snapshots the file in
    preparation for
    versioning.
    git commit
    Records file snapshots
    permanently in version
    history.
    git log
    Lists version history for
    a file.
    git rm --cached
    Removes the file from
    version control but
    preserves the file
    locally.
    git status
    Lists all new or modified
    files to be committed.
    21

    View full-size slide

  22. 3
    Synchronizing Work
    Let’s share our work!
    22

    View full-size slide

  23. Synchronizing Work
    23
    https://www.git-tower.com/learn/git/ebook/en/command-line/remote-repositories/introduction

    View full-size slide

  24. Upload Commits
    24
    git push -u
    ▪ Pushing is how you transfer
    commits from your local
    repository to a remote repository
    git remote -v
    git push -u origin master
    git status
    git status

    View full-size slide

  25. Download All History
    25
    git fetch
    ▪ Fetching is what you do when you
    want to see what everybody else has
    been working on.
    git log

    View full-size slide

  26. Incorporate Changes
    26
    git pull
    ▪ Fetch and download content from a
    remote repository and incorporate
    changes.
    git log

    View full-size slide

  27. LET’S REVIEW SOME COMMANDS
    git push
    Uploads all local commits
    to the remote server.
    git fetch
    Downloads all history from
    the repository bookmark
    git pull
    Downloads bookmark history
    and incorporates changes
    27

    View full-size slide

  28. Thanks!
    ANY QUESTIONS?
    You can find me at:
    [email protected]
    28

    View full-size slide

  29. Git: A Distributed Revision
    Control System (Part II)
    Presented by: Jaime Arias

    View full-size slide

  30. 4
    Branching
    Let’s create branches!
    30

    View full-size slide

  31. Create a New Branch
    branch
    31
    ▪ A branch represents an independent line
    of development.
    ▪ A branch is a pointer to a commit.
    git checkout -b
    git branch
    git branch -a
    https://www.atlassian.com/git/tutorials/using-branches

    View full-size slide

  32. Delete a Branch
    branch
    32
    git branch -d
    ▪ Once you’ve finished working on a branch
    and have merged it into the main code
    base, you’re free to delete the branch
    without losing any history.
    git push origin --delete
    git branch -D
    https://www.atlassian.com/git/tutorials/using-branches

    View full-size slide

  33. Switching between Branches
    checkout
    33
    ▪ This command lets you navigate between
    the branches.
    * Atlassian Bitbucket. Resetting, Checking Out & Reverting.
    Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
    git checkout

    View full-size slide

  34. Merging Branches
    merge
    34
    ▪ It takes a sequence of commits of a branch
    and integrate them into a another one.
    ▪ It creates a new “merge commit”
    ▪ It is a non-destructive operation
    * https://www.atlassian.com/git/tutorials/using-branches/git-merge
    git merge

    View full-size slide

  35. Delete Untracked Files
    clean
    35
    git clean -f
    ▪ It deletes untracked files from the current
    directory.
    git clean -n
    git clean -d
    git clean -x

    View full-size slide

  36. Temporarily Stashing Some Changes
    stash
    36
    git stash
    ▪ It temporarily shelves changes (staged/tracked)
    that can be reapplied later on.
    ▪ Useful when you need to quickly switch context
    and work on something else.
    git stash apply
    git stash list
    git stash pop
    git stash drop
    * https://www.atlassian.com/git/tutorials/saving-changes/git-stash

    View full-size slide

  37. LET’S REVIEW SOME COMMANDS
    git branch
    Creates, deletes and lists
    branches.
    git checkout
    Switch branches or restore
    working tree files.
    git merge
    Incorporates changes from
    a branch into the current
    branch.
    git clean
    Removes untracked files
    from the working tree.
    git stash
    Stashes the changes in a
    dirty working directory
    away.
    37

    View full-size slide

  38. GitFlow
    gitflow
    38
    * https://nvie.com/posts/a-successful-git-branching-model/

    View full-size slide

  39. 5
    Rewriting the
    History
    Let’s play with the
    timeline!
    39

    View full-size slide

  40. Rebase a Branch
    rebase
    40
    ▪ Re-writes the project history by creating brand
    new commits for each commit in the original
    branch
    ▪ Trade-offs: safety and traceability
    ▪ Golden Rule: never use rebase on public branches
    * Atlassian Bitbucket. Merging vs. Rebasing. url: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

    View full-size slide

  41. Reset to a Previous Commit
    reset
    41
    ▪ Versatile tool for undoing changes.
    ▪ Forms of invocation: --soft, --mixed, --hard
    ▪ It moves both the HEAD and branch refs to a
    specific commit.
    * Atlassian Bitbucket. Resetting, Checking Out & Reverting.
    Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting

    View full-size slide

  42. Reset to a Previous Commit
    reset
    42
    ▪ Versatile tool for undoing changes.
    ▪ Forms of invocation: --soft, --mixed, --hard
    ▪ It moves both the HEAD and branch refs to a
    specific commit.
    * Atlassian Bitbucket. Resetting, Checking Out & Reverting.
    Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting

    View full-size slide

  43. Revert a Previous Commit
    revert
    43
    ▪ Revert a commit that made changes you
    want to undo.
    ▪ Reverting undoes a commit by creating a
    new commit.
    ▪ It is a “safe” way to undo changes
    * Atlassian Bitbucket. Resetting, Checking Out & Reverting.
    Url: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting

    View full-size slide

  44. LET’S REVIEW SOME COMMANDS
    git rebase
    Re-applies commits on top
    of another base tip.
    git reset
    Resets current HEAD to a
    specific state.
    git revert
    Reverts some existing
    commits.
    44

    View full-size slide

  45. Thanks!
    ANY QUESTIONS?
    You can find me at:
    [email protected]
    45

    View full-size slide

  46. CREDITS
    Special thanks to all the people who made and released
    these awesome resources for free:
    ▪ Presentation template by SlidesCarnival
    ▪ Photographs by Unsplash
    ▪ Stickers by Telegram
    46

    View full-size slide