git and github - verson control for the modern developer

51
Git & Github - version control for the modern developer by John Stevenson @jr0cket git.practical.li

Upload: john-stevenson

Post on 18-Jan-2017

875 views

Category:

Software


5 download

TRANSCRIPT

Page 1: Git and github - Verson Control for the Modern Developer

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
Page 3: Git and github - Verson Control for the Modern Developer

Why Git / Version controlHelping us manage and collaborate

Page 4: Git and github - Verson Control for the Modern Developer

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

History at your fingertipsgit log --oneline --decorate

Page 6: Git and github - Verson Control for the Modern Developer

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

What is Git...it's not just me when I am being grumpy...

Page 8: Git and github - Verson Control for the Modern Developer

Distributed vs Centralised model

Page 9: Git and github - Verson Control for the Modern Developer

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
Page 11: Git and github - Verson Control for the Modern Developer

Distributed model in action

Page 12: Git and github - Verson Control for the Modern Developer

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

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

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

Tools to Gitchoose your tools and learn them well...

Page 16: Git and github - Verson Control for the Modern Developer

- Windows & MacOSX

desktop.github.com

Page 17: Git and github - Verson Control for the Modern Developer

Emacs Magit - very powerful & easy to use

Page 18: Git and github - Verson Control for the Modern Developer

SourceTree - Atlassian

Page 19: Git and github - Verson Control for the Modern Developer

GitKraken.com

Page 20: Git and github - Verson Control for the Modern Developer

Git Command Line

Page 21: Git and github - Verson Control for the Modern Developer

Git local workflowversion your changes locally, before sharing them

Page 22: Git and github - Verson Control for the Modern Developer

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

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

Git Visual Cheatsheet ndpsoftware.com/git-cheatsheet.html

Page 25: Git and github - Verson Control for the Modern Developer

Collaborating with Githubadditional services around Git

Page 26: Git and github - Verson Control for the Modern Developer

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
Page 28: Git and github - Verson Control for the Modern Developer

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

Creating a repository

Page 30: Git and github - Verson Control for the Modern Developer

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

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

Submit a pull request

Page 33: Git and github - Verson Control for the Modern Developer

Github Pull Request - Accepted & Merged

Page 34: Git and github - Verson Control for the Modern Developer

Github Pull Request - Code Review

Page 35: Git and github - Verson Control for the Modern Developer

Visualising Github - ghv.artzub.com

Page 36: Git and github - Verson Control for the Modern Developer

Branching & Mergingbranches should allow experimentation, merging should be simple

Page 37: Git and github - Verson Control for the Modern Developer

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

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

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

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

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

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

Deploying with GitGit can be an important part of your release management

Page 44: Git and github - Verson Control for the Modern Developer

Example: Heroku

git push heroku master

Page 45: Git and github - Verson Control for the Modern Developer

Example: Heroku

git push heroku master

Page 46: Git and github - Verson Control for the Modern Developer
Page 47: Git and github - Verson Control for the Modern Developer

Learning Git in-depthwe learn by example...

Page 48: Git and github - Verson Control for the Modern Developer

Books on Git

progit.org

gitforteams.com

Page 49: Git and github - Verson Control for the Modern Developer

atlassian.com/git/tutorials

Page 50: Git and github - Verson Control for the Modern Developer

Take your own journey into Git

Page 51: Git and github - Verson Control for the Modern Developer

Thank you

@jr0cketjr0cket.co.uk