An introduction to Git and Github, tools for distributed version control that give an easy to use and highly collaborative approach to version code and configuration.
6. 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
9. Distributed vs Centralised model
Centralised
- 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
13. Install a Git Client
Install your prefered Git Client
git-scm.com/downloads/guis
14. Identifying yourself with Git
Labels every commit you make with your identity
git config --global user.name “John Stevenson”
git config --global user.email “john@jr0cket.co.uk”
Git graphical clients also allow you to set your identity and usually save this
into your ~/.gitconf file
22. Create a local repository:
git init
Edit your source code (working copy)
Add changes you want to capture in the
next commit
git add filename or file pattern
See what files you have changed / added
git status
Compare changes in working copy
git diff filename
git diff --cached filename
23. Create a commit from the added files:
git commit -m “meaningful message”
See the current history of commits
git log --oneline --decorate
See the contents of a commit
git show commit-number
Dont delete the .git directory or you
loose all the history of the project
26. 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
27.
28. Authentication methods
- SSH Keys vs Passwords
SSH 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
37. Branching
Branches 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)
38. Creating a branch
git 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
39. 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 change
git push remote branch-name
Or simply delete a branch reference on the remote git repository
git push remote --delete branch-name
41. 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