Slide 1

Slide 1 text

GIT BACK TO BASICS Angel Thomas @starangel75

Slide 2

Slide 2 text

ABOUT ME Angel Thomas Software Developer 
 Center for Information Management @starangel75
 https://speakerdeck.com/astahre/git-back-to-basics-codemash-2020

Slide 3

Slide 3 text

?

Slide 4

Slide 4 text

WHAT IS GIT? Git is a Distributed Version Control System

Slide 5

Slide 5 text

WHAT IS VERSION CONTROL? Any system that records changes over time

Slide 6

Slide 6 text

TYPES OF VERSION CONTROL Old School: We just saved another copy with a slightly different name

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

TYPES OF VERSION CONTROL Centralized: There is one central copy of the project

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

TYPES OF VERSION CONTROL Decentralized: Each contributor has the project

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

GIT VOCABULARY Repository: a central location in which data is stored and managed

Slide 13

Slide 13 text

GIT VOCABULARY Repository: a central location in which data is stored and managed Fork: a copy of a repository on a remote server

Slide 14

Slide 14 text

GIT VOCABULARY Repository: a central location in which data is stored and managed Fork: a copy of a repository on a remote server Clone: a local copy of a repository

Slide 15

Slide 15 text

INIT git init Creates a new git repository. This can be an empty project or to convert an existing project.

Slide 16

Slide 16 text

CONFIG git config Set configurations for git

Slide 17

Slide 17 text

CONFIG git config --global --edit Edit the git configuration file. These changes will be made in the default editor

Slide 18

Slide 18 text

CONFIG git config --global user.name “Angel Thomas” git config --global user.email [email protected] Set identity information for configuration file without opening the editor

Slide 19

Slide 19 text

CONFIG git config --list Check configuration settings

Slide 20

Slide 20 text

CONFIG git config --global core.editor emacs git config --global core.editor vim Set preferred editor

Slide 21

Slide 21 text

CLONE git clone hosting-service.com/username/repository-name (this can be ssh or https) Download a copy of a repository and create a local copy

Slide 22

Slide 22 text

BRANCH git branch List branches in the current repository and indicate what branch is active

Slide 23

Slide 23 text

BRANCH git branch newBranch Create a new branch

Slide 24

Slide 24 text

BRANCH git branch feature/newBranch Create a new feature branch

Slide 25

Slide 25 text

CHECKOUT git checkout Switch to a branch

Slide 26

Slide 26 text

CHECKOUT git checkout -b Create a branch and switch to it

Slide 27

Slide 27 text

NEW IN GIT 2.23 git switch Switch branches. This would replace checkout. * This is experimental and may change

Slide 28

Slide 28 text

CONFIG . . AGAIN git config --global alias.co checkout git config --global alias.br branch git config --global alias.st status Set some aliases

Slide 29

Slide 29 text

FETCH git fetch Fetch any commits that are on the remote repository that are not in the local repository

Slide 30

Slide 30 text

MERGE git merge Merge commits that have been fetched or merge in another branch

Slide 31

Slide 31 text

PULL git pull Combination of fetch and merge

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

STATUS git status Check the status of the local repository

Slide 34

Slide 34 text

DIFF git diff Display changes that have not yet been staged

Slide 35

Slide 35 text

ADD git add <filename> Add a file to the staging area

Slide 36

Slide 36 text

ADD git add . Add all files to the staging area

Slide 37

Slide 37 text

COMMIT git commit -m “commit message” Commit all changes

Slide 38

Slide 38 text

COMMIT git commit --amend no-edit Any file changes made will be added to the commit without changing the commit message

Slide 39

Slide 39 text

COMMIT git commit --amend -m “commit message” Change the commit. This would include file changes and change it to the new commit message.

Slide 40

Slide 40 text

PUSH git push Push changes from local repository to remote

Slide 41

Slide 41 text

PUSH git push -- force Push changes from local repository to remote removing commits that are on the remote that do not exist on the local

Slide 42

Slide 42 text

PUSH git push -- force-with-lease Push changes from local repository to remote removing your commits that are on the remote that do not exist on the local, but failing if there are commits by others

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

REMOTE git remote List remotes

Slide 45

Slide 45 text

PULL REQUEST Submit changes to be merged into the primary repository.

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

LOG git log List the log of commits

Slide 49

Slide 49 text

DIFF git diff Display changes between two commits

Slide 50

Slide 50 text

RESET git reset Discards changes, but changes are still available

Slide 51

Slide 51 text

RESET git reset Discards changes after specified commit, but changes are still available

Slide 52

Slide 52 text

RESET git reset --hard Discards all history/changes that have not been committed

Slide 53

Slide 53 text

NEW IN GIT 2.23 git restore <file> Discard changes made to the file * This is experimental and may change

Slide 54

Slide 54 text

REFLOG git reflog Show what is recorded in the reflog

Slide 55

Slide 55 text

STASH git stash Temporarily save changes made

Slide 56

Slide 56 text

STASH git stash list Show a list of stashed file changes

Slide 57

Slide 57 text

STASH git stash pop Apply changes from the top item in the stash list to the current branch

Slide 58

Slide 58 text

CLEAN git clean -n Show which files would be removed from the working directory

Slide 59

Slide 59 text

CLEAN git clean -f Remove files from the working directory

Slide 60

Slide 60 text

MERGE CONFLICTS A merge conflict occurs when git is unable to automatically resolve the difference in changes between two or more commits.

Slide 61

Slide 61 text

MERGE CONFLICTS Mergetools Kdiff3 P4Merge Beyond Compare DiffMerge Semantic Merge

Slide 62

Slide 62 text

REVERT git revert A commit that reverses the work in the last commit

Slide 63

Slide 63 text

REVERT git revert A commit that reverses the work done in the specified commit

Slide 64

Slide 64 text

RESET git reset --hard Discards all history/changes after specified commit

Slide 65

Slide 65 text

REBASE git rebase / Apply commits from the current branch to follow the commits of the remote branch

Slide 66

Slide 66 text

REBASE git rebase Apply commits from the current branch to follow the commits of the specified local branch

Slide 67

Slide 67 text

REBASE git rebase Apply commits from the current branch to follow the specified commit

Slide 68

Slide 68 text

REBASE git rebase -i Opens in interactive window with all commits from the specified to the most recent

Slide 69

Slide 69 text

REBASE git rebase -i HEAD~5 Opens in interactive window with the 5 most recent commits

Slide 70

Slide 70 text

SQUASH git merge --squash Convert the commits of a specified branch into a single commit and merge it into the current branch

Slide 71

Slide 71 text

CHERRY-PICK git cherry-pick Apply commit from another branch to the current branch

Slide 72

Slide 72 text

BISECT git bisect start Start a bisect

Slide 73

Slide 73 text

BISECT git bisect good Indicate that a commit is good

Slide 74

Slide 74 text

BISECT git bisect bad Indicate that a commit is bad * Can also use old/new

Slide 75

Slide 75 text

RESOURCES https://git-scm.com/doc
 https://www.atlassian.com/git/tutorials/atlassian-git- cheatsheet https://education.github.com/git-cheat-sheet-education.pdf https://about.gitlab.com/images/press/git-cheat-sheet.pdf http://gitimmersion.com/