• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Essential git for developers
 

Essential git for developers

on

  • 2,180 views

You have been wanting to use the "new shiny", but there are too many "Git how-tos" out there and you don't kow where to start. This is not another one of those. Instead Adam Culp will give a practical ...

You have been wanting to use the "new shiny", but there are too many "Git how-tos" out there and you don't kow where to start. This is not another one of those. Instead Adam Culp will give a practical walk through the development cycle and how to use Git as the source control. From initialization of a repository, to forking, cloning, and checkout, we will walk through a sample project and how most developers actually use Git to manage the workflow. Adam will also touch on how to use Git repository hosting providers, and how to use them with PAAS (Platform as a service) providers.

Statistics

Views

Total Views
2,180
Views on SlideShare
2,132
Embed Views
48

Actions

Likes
8
Downloads
2
Comments
0

3 Embeds 48

http://librosweb.es 37
http://lanyrd.com 8
https://twitter.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Essential git for developers Essential git for developers Presentation Transcript

    • Essential Git For Developers Essential Git For Developers By: Adam Culp Twitter: @adamculp https://joind.in/10046
    • Essential Git For Developers ● About me – – Work at Zend Technologies – Organizer SoFloPHP (South Florida) – Organized SunshinePHP (Miami) – Long distance runner – 2 PHP 5.3 Certified Judo Black Belt Instructor
    • Essential Git For Developers ● Fan of iteration – Everything requires iteration to do well: (practice makes perfect) ● ● Judo ● Development ● Avoid project managers ● 3 Long distance running Version Control!
    • Essential Git For Developers ● Why use Git? – No centralization ● – No central server (unless desired) Each clone = full repository. ● Git tracks state, history, and integrity. – Branching and Merging work. – Fast ● Operations performed local. ● Only one .git directory. – – Free and Open Source – 4 Files to be committed are “staged” first. Flexible workflow
    • Essential Git For Developers ● How Others Looks At Data. – As files and the changes made to each file. Version 1 Version 2 File A Version 3 Diff 1 Diff 1 5 Diff 1 Version 5 Diff 2 File B File C Version 4 Diff 2 Diff 2 Diff 3
    • Essential Git For Developers ● How Git Looks At Data. – As whole files, not files + diffs. Version 1 Version 2 Version 3 Version 4 Version 5 File A File A1 File A1 File A2 File A2 File B File B File B File B1 File B2 File C File C1 File C2 File C2 File C3 Green means whole file, yellow means pointer to previous whole file. 6
    • Essential Git For Developers ● Subversion-Style Workflow Shared Repository Developer 7 Developer Developer
    • Essential Git For Developers ● Integration Manager Workflow Blessed Repository Integration Manager 8 Developer Public Developer Public Developer Private Developer Private
    • Essential Git For Developers ● Dictator and Lieutenants Workflow Blessed Repository Dictator Lieutenant Lieutenant Developer 9 Developer Developer Developer
    • Essential Git For Developers ● Single Developer – One repository, everything in one basket. ● Remember to backup Developer Local Repository 10
    • Essential Git For Developers ● 11 Each 'git clone' == full repository
    • Essential Git For Developers ● What is actually going on? – A bunch of repositories! Repository Repository 12 Repository Repository
    • Essential Git For Developers ● But it could be: – Repositories can connect in all directions. Repository Repository Repository Repository 13
    • Essential Git For Developers ● Most common commands – – git init – git clone – git status – git add – git commit – git log or show – git branch – git checkout – git merge – 14 git config git pull or push
    • Essential Git For Developers ● Help on all commands – 15 Adding '-h' to any command will return help on usage.
    • Essential Git For Developers ● git config – – 16 Easily set your information to accompany commits. Generally a one time thing.
    • Essential Git For Developers ● git init – – 17 Instruct Git to track project by simply 'git init'. No more excuses! Version all the things!
    • Essential Git For Developers ● git clone {repo} {destination} – Creates new repository based on another. – Cloned repository becomes “Origin”. ● 18 Internal pointer for where it came from.
    • Essential Git For Developers ● Example of 'git clone' – – We address the .git directory. – 19 Below we clone a repo from github. Specify where to put it.
    • Essential Git For Developers ● git status – 20 Provides status of resources in the tracked project.
    • Essential Git For Developers ● git status – 21 Below 'git status' informs us of untracked files after created.
    • Essential Git For Developers ● git add – 22 Stages files to be committed.
    • Essential Git For Developers ● git commit – A 'git commit' includes all “staged” files. – Use '-m' to store a message with the commit. ● 23 Or git prompts user to add a message. (using default editor)
    • Essential Git For Developers ● More on commits – A commit should be: ● Done OFTEN! ● Commit messages Always included – Short – Informative Single commit per bug or ticket. – ● 24
    • Essential Git For Developers ● git log – – 25 Shows history of prior commits. We've only done one, and here it is:
    • Essential Git For Developers ● git show {commit hash} – – 26 Hash optional, will show previous by default. Shows commit + diff view of files.
    • Essential Git For Developers ● What would a commit do? – 27 We did a 'git add' for file #2, and modified file 1.
    • Essential Git For Developers ● And now? – 28 We did a 'git add' for modified file 1.
    • Essential Git For Developers ● And finally? – 29 We did a 'git add' for new file 3.
    • Essential Git For Developers ● After the commit. – – 30 All staged files were added. A 'git status' reveals nothing new or different.
    • Essential Git For Developers ● Commits do not carry a version # – – 31 Git doesn't use numbers like 1, 2, 3... Instead uses hashes like 6e7e6999c879f460b5e1d7e29ffe9907062ec20a
    • Essential Git For Developers ● Working in 'master' is bad. – Should not be working in the 'master' branch. – 'master' should be pristine version. ● ● Tested ● 32 Most bug free. Same as “Production”
    • Essential Git For Developers ● git branch – – 33 Shows a list of existing branches. The * indicates active branch.
    • Essential Git For Developers ● git branch {name} {branch} ● Or git checkout -b {name} {branch} – – Checkout -b checks out after creation. – Below we create a 'development' branch. – 34 Creates new branch. New branch has same state as active/specified branch.
    • Essential Git For Developers ● git checkout {name} – – Switches to a specified branch. – Branches carry own state. – 35 Include “-b” flag to create new branch. In file browser file contents different.
    • Essential Git For Developers ● What if? – – We are in 'development' branch. – 36 A file has been edited, but not committed. What if we 'git checkout master'?
    • Essential Git For Developers ● Change branch with uncommitted files – Merges uncommitted content on checkout. ● Whether 'staged' or not. – – 37 Does NOT merge over newly created files. (changes only) Conflicts get exciting. (Not covered in this talk.)
    • Essential Git For Developers ● File not actually changed – On 'git checkout development' and commit: ● File in development carries edit committed. ● File in master is reset, even though merged previously. master 38 development
    • Essential Git For Developers ● But if commit done first – Commit only done on active branch. – Master branch is unchanged. ('git log' shown below) – Master files do not contain merged changes. master 39 development
    • Essential Git For Developers ● git merge {branch} – Git merges specified branch into active branch. – We merge change from development to master. ● ● 40 'git checkout master' 'git merge development'
    • Essential Git For Developers ● What are “fast forward” commits? – 41 Merges individual commits into flow as if a checkout never occurred.
    • Essential Git For Developers ● Ignoring files from repository – We can exclude: ● ● 42 Folders ● – Files Config files with passwords ! ! ! Simply add excluded content to the file '.gitignore'.
    • Essential Git For Developers ● Typical branches for teams – Conventions: ● ● Development public, public to all. ● 43 Testing, Staging and Master branches off limits but public. {user}-development branches local and private.
    • Essential Git For Developers ● Typical rules for branch usage – No code leaves {user}-development unless finished and stable. ● – 44 Developers merge to development branch...period! Do NOT merge conflicts into any public branch.
    • Essential Git For Developers ● Commit procedure (origin pull/merge/push) – Before merging changes to public development: ● 'git checkout development' ● 'git pull origin development' Should be no conflicts. 'git checkout {user}-development' – ● ● 'git merge development' Fix conflicts 'git checkout development' – ● ● ● 45 'git merge {user}-development' 'git push origin development'
    • Essential Git For Developers ● Public and Private branches – Typically {user}-development branches remain private. ● ● – The team is not aware of commits done there. Frequent commits encouraged. Development, Staging, and Master are public and entire team can view state/commits. ● ● 46 All developers can merge to development. Only authorized people can merge to staging or master.
    • Essential Git For Developers ● Team Developer workflow – 47 Git is ideal for team development
    • Essential Git For Developers ● Team Developer workflow (private) – Project/ticket assigned, create branch ● 'git checkout development' ● 'git branch {user}-development' or 'git checkout -b {user}-development' – Start coding. – Commit often. Project assigned 48 Checkout dev. to private {user}-development
    • Essential Git For Developers ● Team Developer workflow (private) – Regularly commit code. ● ● – 'git add {filename}' X each file 'git commit -m {commit message}' Regularly pull from origin. ● 'git checkout development' followed by 'git pull origin development' ● 'git checkout {user}-development' followed by 'git merge development' Project assigned 49 Checkout dev. to private {user}-development Coding Multiple commits
    • Essential Git For Developers ● Team Developer workflow (private) – Development completed, ready for QA testing. ● 'git checkout development' ● 'git pull origin development' should be no conflicts. ● 'git merge {user}-development' should be no conflicts. Project assigned Tests pass 50 Checkout dev. to private {user}-development Merge changes to development Coding Multiple commits
    • Essential Git For Developers ● Team QA workflow (public) – Testing done in development branch. – Failed → developer picks up on {user}-development. – Bug fixed → re-push to development. Return to developer flow no Testing assigned 51 Testing from development Test passed
    • Essential Git For Developers ● Team QA workflow (public) – Testing done in development branch. – Success → merge to staging ● 'git checkout staging' ● 'git pull origin staging' ● 'git merge development' ● 'git push origin staging' Return to developer flow no Testing assigned 52 Testing from development Test passed yes Merge to staging
    • Essential Git For Developers ● Team Deployment Mgr. workflow (public) – Regression testing done in staging branch. – Testing failed: ● – 'git branch -b {tempname}-staging' Code to fix bug ● 'git add {files}' ● 'git commit -m {message}' Temp branch created no Deploy assigned 53 Regression testing In staging Test passed
    • Essential Git For Developers ● Team Deployment Mgr. workflow (public) – Send fix back for regression testing done in staging branch. ● 'git merge staging' just to check for conflicts. ● 'git checkout staging' ● 'git merge {tempname}-staging' Bug fixed Temp branch created no Deploy assigned 54 Regression testing In staging Test passed
    • Essential Git For Developers ● Team Deployment Mgr. workflow (public) – If regression tests pass: ● 'git merge master' in case of conflicts ● 'git checkout master' then 'git pull origin master' ● 'git merge staging' Bug fixed Temp branch created no Deploy assigned 55 Regression testing In staging Test passed yes Merge to master
    • Essential Git For Developers ● Team Deployment Mgr. workflow (public) – All is good, create annotated tag. ● 'git tag -a v1.0 -m '{message}' (Note: 'git tag' lists all tags.) Bug fixed Temp branch created no Deploy assigned Regression testing In staging Test passed yes Tag created 56 Merge to master
    • Essential Git For Developers ● Single Developer workflow (small project) – Pretty similar, but no staging. – Note: Still use {user}-development per task/project/ticket. 57 {user}-development Test passed Merge to development Tag created Project assigned Merge to master Test passed
    • Essential Git For Developers ● Tools – gitk – gitx – git-cola – SmartGit – GitEye – TortoiseGit – IDE ● Eclipse Zend Studio – Aptana PHPStorm – ● ● 58 etc.
    • Essential Git For Developers ● github.com – – Promotes collaboration – API enhances connectivity and use – Awesome plugins – 59 Great place to share code. Easy to use
    • Essential Git For Developers ● github - home – 60 Easy to find your stuff
    • Essential Git For Developers ● github – what to clone locally – 61 Click to highlight URL for 'git clone' call.
    • Essential Git For Developers ● github – how to clone locally – – Now have a clone local to work on. – 62 Standard 'git clone' command Follow workflow as shown earlier.
    • Essential Git For Developers ● Bitbucket.org – – 63 Another source control host Different pricing model
    • Essential Git For Developers ● phpcloud.com – – Development environment hosting (not production) – Deploy to any cloud provider when ready to go LIVE! – Zend Server – Zend Framework – Zend Debugger – 64 Git hosting FREE!!!
    • Essential Git For Developers ● Conclusion – – Git is an easy solution, just 'git init'. – Plan a workflow and stick with it...ALWAYS! – 3rd party repositories = backed up – Git easy to connect to from anywhere. – 65 Always use source control!!! Love iteration!
    • Essential Git For Developers ● Resources – – http://github.com – http://training.github.com/ – https://bitbucket.org/ – http://phpcloud.com – 66 http://nvie.com/posts/a-successful-git-branching-model/ http://git-scm.com
    • ● Thank you! – Please rate at: https://joind.in/10046 Essential Git For Developers Adam Culp http://www.geekyboy.com Twitter @adamculp Questions?