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. 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
  2. What is it? 3 * Pro Git book, written by

    Scott Chacon and Ben Straub and published by Apress
  3. 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
  4. Basic Configuration 6 git config --global user.name "Jaime Arias" git

    config --global user.email "[email protected]" git config --global core.editor vim
  5. 12 Working with the Repository * Pro Git book, written

    by Scott Chacon and Ben Straub and published by Apress
  6. 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
  7. 14 Working with the Repository add * Pro Git book,

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

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

    book, written by Scott Chacon and Ben Straub and published by Apress
  10. 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
  11. 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/
  12. 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
  13. Upload Commits 24 git push -u <remote_name> <branch_name> ▪ 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
  14. 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
  15. Incorporate Changes 26 git pull ▪ Fetch and download content

    from a remote repository and incorporate changes. git log
  16. 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
  17. 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 <branch_name> git branch <branch_name> git branch -a https://www.atlassian.com/git/tutorials/using-branches
  18. Delete a Branch branch 32 git branch -d <branch_name> ▪

    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 <branch_name> git branch -D <branch_name> https://www.atlassian.com/git/tutorials/using-branches
  19. 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 <branch_name>
  20. 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 <branch_name>
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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