git and github - verson control for the modern developer
TRANSCRIPT
![Page 1: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/1.jpg)
Git & Github - version control for the modern developerby John Stevenson @jr0cket
git.practical.li
![Page 2: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/2.jpg)
![Page 3: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/3.jpg)
Why Git / Version controlHelping us manage and collaborate
![Page 4: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/4.jpg)
We learn from history, so don't delete it
Those who cannot remember the past are condemned to repeat it
- George Santayana
![Page 5: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/5.jpg)
History at your fingertipsgit log --oneline --decorate
![Page 6: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/6.jpg)
Version control should be easy
Every developer should be able to manage changes without a dedicated version control team
- makes developers more likely to version their software more often- smaller commits- meaningful commit messages - easy merging of changes- easy to experiment & throw away code
![Page 7: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/7.jpg)
What is Git...it's not just me when I am being grumpy...
![Page 8: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/8.jpg)
Distributed vs Centralised model
![Page 9: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/9.jpg)
Distributed vs Centralised modelCentralised
- only 1 server, single version of the truth- typically a locking approach - requires central server setup- single point of failure in central server- only use when connected to the network
Distributed
- only requires git init to start versioning- have the whole project to work with- multiple repositories give redundancy- commit changes offline & fast- easy to share changes & collaborate- need to decide canonical source of truth
![Page 10: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/10.jpg)
![Page 11: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/11.jpg)
Distributed model in action
![Page 12: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/12.jpg)
Getting Started with Git...it's not just me when I am being grumpy...
![Page 13: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/13.jpg)
Install a Git Client
Install your prefered Git Client
git-scm.com/downloads/guis
![Page 14: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/14.jpg)
Identifying yourself with Git
Labels every commit you make with your identity
git config --global user.name “John Stevenson”
git config --global user.email “[email protected]”
Git graphical clients also allow you to set your identity and usually save this into your ~/.gitconf file
![Page 15: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/15.jpg)
Tools to Gitchoose your tools and learn them well...
![Page 16: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/16.jpg)
- Windows & MacOSX
desktop.github.com
![Page 17: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/17.jpg)
Emacs Magit - very powerful & easy to use
![Page 18: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/18.jpg)
SourceTree - Atlassian
![Page 19: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/19.jpg)
GitKraken.com
![Page 20: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/20.jpg)
Git Command Line
![Page 21: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/21.jpg)
Git local workflowversion your changes locally, before sharing them
![Page 22: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/22.jpg)
Create a local repository: git init
Edit your source code (working copy)
Add changes you want to capture in the next commitgit add filename or file pattern
See what files you have changed / addedgit status
Compare changes in working copygit diff filenamegit diff --cached filename
![Page 23: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/23.jpg)
Create a commit from the added files: git commit -m “meaningful message”
See the current history of commitsgit log --oneline --decorate
See the contents of a commitgit show commit-number
Dont delete the .git directory or you loose all the history of the project
![Page 24: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/24.jpg)
Git Visual Cheatsheet ndpsoftware.com/git-cheatsheet.html
![Page 25: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/25.jpg)
Collaborating with Githubadditional services around Git
![Page 26: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/26.jpg)
What is Github
Github is a cloud service for managing & sharing changes
- provides private & public repositories- repository forks & pull requests- collaborative code review- Gists for single file sharing
Github pages website publishing
- markdown driven content
![Page 27: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/27.jpg)
![Page 28: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/28.jpg)
Authentication methods - SSH Keys vs PasswordsSSH authentication
- uses a public/private key to authenticate, so no passwords - keys needs to be added to each computer you use
Password authentication
- account can be cached to minimise typing of credentials
![Page 29: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/29.jpg)
Creating a repository
![Page 30: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/30.jpg)
Cloning a Github RepositoryClone (copy completely) an existing repository, giving an optional directory name
git clone URL directory-name
![Page 31: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/31.jpg)
Forking a Github RepositoryYou can fork to your account or any Github Organisation you belong too
![Page 32: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/32.jpg)
Submit a pull request
![Page 33: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/33.jpg)
Github Pull Request - Accepted & Merged
![Page 34: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/34.jpg)
Github Pull Request - Code Review
![Page 35: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/35.jpg)
Visualising Github - ghv.artzub.com
![Page 36: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/36.jpg)
Branching & Mergingbranches should allow experimentation, merging should be simple
![Page 37: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/37.jpg)
BranchingBranches allow you to work on
- specific features- bug fixes - ideas / experiments
Branches can
- merged into another branch- have commits cherry picked- be discarded easily- be attached to another branch or be
stand alone (eg. gh-pages)
![Page 38: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/38.jpg)
Creating a branchgit branch branch-name ;; create a branch attached to the current branch
git checkout branch-name ;; checkout branch so new commits are added to it
git checkout -b branch-name ;; both commands above in one command
git branch ;; lists all branches
Creating a stand alone (orphan) branch
git branch -o branch-name ;; branch independent of others & shares no history
![Page 39: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/39.jpg)
Branching - discarding
Branches can live forever, the longer they live become harder to merge git branch -d branch-name
If this branch is also on a remote git repository, you need to push this changegit push remote branch-name
Or simply delete a branch reference on the remote git repositorygit push remote --delete branch-name
![Page 40: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/40.jpg)
Merging
Checkout branch to receive the merge commits
git checkout master
git merge feature
![Page 41: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/41.jpg)
Rebasing - only with consent!
Note: Anything that affects the history should be done with consent,especially once commits are shared
Checkout branch to receive the merge commits
git checkout feature
git rebase master
![Page 42: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/42.jpg)
Cherry Picking
Checkout branch to receive the cherry picked commit
git checkout master
git cherry-pick commit-number
![Page 43: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/43.jpg)
Deploying with GitGit can be an important part of your release management
![Page 44: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/44.jpg)
Example: Heroku
git push heroku master
![Page 45: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/45.jpg)
Example: Heroku
git push heroku master
![Page 46: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/46.jpg)
![Page 47: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/47.jpg)
Learning Git in-depthwe learn by example...
![Page 48: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/48.jpg)
Books on Git
progit.org
gitforteams.com
![Page 49: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/49.jpg)
atlassian.com/git/tutorials
![Page 50: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/50.jpg)
Take your own journey into Git
![Page 51: Git and github - Verson Control for the Modern Developer](https://reader034.vdocuments.site/reader034/viewer/2022042611/587ea1ae1a28ab2a4a8b59a5/html5/thumbnails/51.jpg)
Thank you
@jr0cketjr0cket.co.uk