Dreamforce 13 developer session: Git for Force.com developers

2,728 views
2,423 views

Published on

Git is a powerful version control tool and this presentation shows how Force.com developers can make use of Git in their projects.

Including tips and tricks, this presentation covers the core commands you need to know to use Git effectively. We also cover using Git from the Force.com IDE.

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,728
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
61
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • You don’t need to remember all the commands I show you, there is a quickstart guide to give you a reference to all the common commands you will use first. There is a more detailed “Cheat sheet” available at Dreamforce
  • Insert diagram
  • To keep this nice and simple I am going to create some text files and capture different versions of those files in Git. This shows what each of these commands does, so even if only use Git via Force.com IDE you know what those commands are doing. This helps you make use of Force.com IDE more efficiently.
  • Diff’ing
  • Diff’ing
  • Diff’ing
  • Diff’ing
  • Diff’ing
  • Diff’ing
  • Diff’ing
  • TODO – fix diagram – git diff next to local repo shold not have the –cached option, it should be on the git diff against staging
  • Diff’ing
  • Diff’ing
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • A bare repository is one without a working directory. Files cannot be added, as the repository can only receive changes via a push to it.
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Taking tips from the Blog Sandeep wrote on using Git.
  • Taking tips from the Blog Sandeep wrote on using Git.
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Add screenshots of using Eclipse and …
  • Dreamforce 13 developer session: Git for Force.com developers

    1. 1. Git for Force.com Developers Managing code and Collaborating on projects John Stevenson Developer Evangelist Salesforce.com @jr0cket
    2. 2. Safe harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
    3. 3. What is this talk about Understanding the value of Git Taking your first steps Git Using Git for Force.com projects Collaborating with Git & Github
    4. 4. The value of Git
    5. 5. Understanding the value of Git Manage your code changes over time - understanding which version of your code is deployed - rollback & compare to earlier versions Experiment with code using branching - branches are easily thrown away or merged if they are valuable Collaborate easily - share code commits using distributed nature of Git
    6. 6. Getting Started with Git
    7. 7. Taking your first steps Git Install Git http://git-scm.com/ Identify yourself to git git config --global user.name “” Create your first repository git config --global user.email “” git init
    8. 8. Salesforce Git Cheat Sheet available in the Developer Library
    9. 9. The common Git commands
    10. 10. Creating a Git repository locally Create a place to manage your changes - stored in a folder called .git git init Removing the .git folder from your project removes any version control and you will loose your change history
    11. 11. Adding files You can tell git which file(s) you want to make part of the next commit (version) - either a specific file name or pattern, or using . every change is added git add filename git add .
    12. 12. Understanding what has changed Git Status gives an overview of local file changes - you will use this command very often git status Git status helps you keep track of your changes and which ones to make part of the next commit.
    13. 13. Creating a commit (version) Create a commit with all the files in staging - providing a message to describe this commit git commit -m “useful commit message” Commit messages help the team quickly review changes and versions
    14. 14. Tracing your commits with Git log Quickly review your change history - this is where good commit messages speed things up git log git log --oneline --graph --decorate The default output of Git Log is basic, if you use the command line then create an alias with your preferred options
    15. 15. Create an alias for git log Save yourself some typing by creating aliases - these are saved in the file ~/.gitconfig git config alias.lg “log –oneline --graph –decorate” You can also edit the ~/.gitconf file directly (if you are careful)
    16. 16. Seeing what code has changed Compare your working files with existing commits - helps you understand what changed, what should be committed next git diff git diff --cached The --cached option compares the working directory with the staged files rather than committed changes.
    17. 17. Staging and committing Staging allows you to group changes across multiple files easily - easier to un-stage files than remove from a commit - gives another step to manage and compare changes A Staged file is over-written when you “git add” the same file - staging does not create a version - commit when you have a meaningful (set of) change(s)
    18. 18. Share your changes with others We work in teams, so we can share our commits - via Github, an internal Git server or directly between developers git push repository branch git archive my-project.zip An archive file (.tar or .zip) will contain the entire history of your code by default
    19. 19. Using Git with Force.com IDE
    20. 20. Getting Force.com IDE Download Eclipse version 4.2 or 4.3 - get the Java Developer edition Add the Force.com IDE plugin Eclipse uses a plugin called EGit to work with local and remote repositories, this is part of the Java Developer version
    21. 21. Identifying yourself to Git with Force.com IDE You will be prompted for your user information when you create your first commit
    22. 22. Identifying yourself to Git with Force.com IDE Force.com IDE will use ~/.gitconfig if it already exists
    23. 23. Using Git for Force.com projects Window > Open Perspective > Git repository exploring
    24. 24. Creating a repository with Force.com IDE
    25. 25. Creating a repository with Force.com IDE Provide the location and name for your local repository Don’t select a bare repository as you will not be able to use a working directory
    26. 26. Creating a repository with Force.com IDE
    27. 27. Using Git & Force.com IDE with an Apex project Using the Apex Workbook as the example project
    28. 28. Creating a Developer Org Create a new developer Org - via developer.force.com Install a package to create the custom objects our Apex code is going to work with - http://bit.ly/ApexWorkbookPackage1_4
    29. 29. Load data into your Developer Org Open the Developer Console 1) click Debug > Open Execute Anonymous Window 2) the Enter Apex Code window is displayed 3) Enter the following apex code and execute ApexWorkbook.loadData();
    30. 30. Creating a new project in Force.com IDE
    31. 31. Change to the Force.com Perspective See the newly created project
    32. 32. Create your first Apex class
    33. 33. Code your Apex class
    34. 34. New Class files marked as untracked New files and their parent folders are marked with ?
    35. 35. Adding the HelloWorld class to Git Switch to Git Repository Exploring perspective Right-click the file name and select Add to Git index
    36. 36. Comparing additional changes with staging
    37. 37. Committing your new code locally Enter a useful commit message and press commit
    38. 38. Syncronize your changes with your Org
    39. 39. View the local commit history
    40. 40. View details of a commit
    41. 41. Github Social Coding
    42. 42. Collaborating with Github Collaborate as a team Work on Open Source projects Get contributions from anyone in the world Include code review into your change management
    43. 43. Creating, Forking & Cloning Creating a repository & Forking a repository - via the Github website Cloning a repository (get a local copy) git clone alias repository-address
    44. 44. Sharing changes back to Github Git Push sends all commits that are only in your local repository to Github Specify with repository (alias name) and branch you want to share git push alias branch
    45. 45. Cloning a repository in Force.com IDE
    46. 46. Tips when using Github & Force.com IDE
    47. 47. Be wary of what you name your project Project & Git repository names should match A repository on Github has a web address (URL) - avoid using spaces and special characters Suggested approach - create your repository on Github first - clone your github repository to your laptop - create a project in Force.com
    48. 48. Commit changes before sync’ing Commit changes before syncing or merging with your org - ensure you don’t loose local changes - commit before using “Save to Server” or “Synchronize with Server” Create a branch if you are not sure you want to keep your code changes - or use “git stash” if you have many unrelated changes
    49. 49. Drive all changes locally Avoid making changes directly on the Org - or sync changes to locally as soon as you make them Changes on the server are too easy to forget - can make merging changes more complicated - more likelihood of merge conflicts, meaning more work for the team
    50. 50. Where to go next try.git.com – free online interactive training Git Visual Cheetsheet – interactive command reference Salesforce Git Cheatsheet - available at Dreamforce in the Developer Library Practice !
    51. 51. Thank you John Stevenson Developer Evangelist @jr0cket git-scm.com try.github.com developer.force.com blog.jr0cket.co.uk

    ×