Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

1 Starter Kit Let’s start with git 5

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

2 Working Locally Let’s create commits! 11

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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/

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

3 Synchronizing Work Let’s share our work! 22

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

4 Branching Let’s create branches! 30

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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