Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Nina Zakharenko - Introduction to Git - Start SLC 2015

1,800 views

Published on

An introduction to git and github, presented by Nina Zakharenko at Start SLC 2015 on behalf of Girl Develop It.

Prerequisites for exercises: installing git on your local machine, creating a github.com account.

Published in: Technology

Nina Zakharenko - Introduction to Git - Start SLC 2015

  1. 1. Start slc Salt Lake City, UT January 31st, 2015
  2. 2. Intro to git PRESENTED BY Nina Zakharenko AND
  3. 3. PART 1 Overview WHY USE VERSION CONTROL COMMITTING TO YOUR REPOSITORY GIT IS NOT GITHUB REPOSITORY CREATE YOUR FIRST GIT PROJECT
  4. 4. PART 2 OVERVIEW FINAL EXERCISEFORKING (IS NOT A DIRTY WORD) BRANCHES PULL REQUESTS SHARING YOUR WORK
  5. 5. ? WHY USE VERSION CONTROL
  6. 6. Have you ever found yourself creating multiple versions of a file to “save” your changes? ! Do you make multiple copies of files to make sure you have a working backup? VERSION PROBLEMS AND VERSIONS ARE ALL OF THEM. I GOT 99 PROBLEMS
  7. 7. Version Control lets you maintain a history of your files. ! This history is easily browsed, attached to author names, and logged with extra commit information. ! This is especially useful when working in a team environment. VERSION CONTROL
  8. 8. Git is a tool. ! More specifically, it’s an open source distributed version control system with an emphasis on data integrity and speed. GIT IS NOT GITHUB GIT github.com is a commercial website that allows you to host git repositories ! You can use it to find many open source projects, and even share your own. GIT HUB You might hear these terms used interchangeably. They’re not the same!
  9. 9. OUR FIRST repo
  10. 10. LINGO REPOSITORY Local Repository - Where code is stored on your local machine ! Remote Repository - Where code is stored on a remote server (github, or internal server) ! Git stores information about the repository in a hidden .git directory contained in the same folder as the project. ! Will be commonly referred to as a repo. ! !
  11. 11. LINGO CLONE Copying a github repository to your local machine.
  12. 12. Let’s configure git on our local computer. ! Use the same email address that your github account is associated with. ! $ git config --global user.name "Your Name Here” ! $ git config --global user.email "your_email@youremail.com" ! SETTING UP GIT SET UP
  13. 13. To set up a git repository locally, we navigate via the command line to the root of our project directory, and run the command: ! $ git init TWO WAYS TO CREATE A REPO LOCALLY Log in to your github account. ! Next, click on the ‘plus’ icon on the right side of the toolbar, then click new repository. ON GITHUB You skip a few setup steps by initializing on github.
  14. 14. GITHUB - CREATE NEW REPO
  15. 15. CLONING OUR NEW REPOSITORY GET THE URL CLONE THE PROJECT LOCALLY
  16. 16. EXERCISE CREATE & CLONE A GITHUB REPO
  17. 17. Creating a fork of my repository will copy it over to your github account. EXERCISE 1. GO TO GITHUB.COM Click the plus button on the right hand side, then select new repository. ! Be aware, public repos are visible on the internet. 2. CREATE A NEW REPOSITORY Copy the clone URL, then type in : ! $ git clone <copied_clone_url_here> 3. COPY THE REPO URL, GIT CLONE
  18. 18. COMMITTING TO YOUR REPOSITORY
  19. 19. LINGO GIT ADD $ git add <filename> ! Git does not automatically keep track of all the files in a project directory. ! Use git add to make it aware of a new file, or use git add on an existing file to let git know you’ve made changes to it that you want to keep.
  20. 20. LINGO THE STAGING AREA When you use $ git add on a file, it gets added to the staging area. ! The staging area contains snapshots of files that will be included in the next commit.
  21. 21. STAGING AREA Source: http://git-scm.com/book/en/v2/Getting-Started-Git- Basics
  22. 22. LINGO GIT STATUS A git command that will give you a status update about your repository. ! This is the command I use the most in my day to day git usage. !
  23. 23. LET’S TRY IT
  24. 24. LINGO GIT COMMIT Record a snapshot of the files in the staging area. ! $ git commit -m “A commit message contains helpful information” ! Note: When we run a $ git status after a commit, we’ll see a message that says “nothing to commit”
  25. 25. LINGO GIT LOG A way to see what changes were made, and by who. ! $ git log !
  26. 26. Use $ git diff <filename> to show the difference between the last checked in version of that file, and the modified file. LINGO DIFF
  27. 27. SIDENOTE WHEN SHOULD I COMMIT MY CODE? Don’t wait for your code to be a in a perfect state before committing it. ! You’ll get the best benefits by committing early & often.
  28. 28. EXERCISE COMMIT A FILE TO OUR REPO
  29. 29. Using the command line, navigate to the repo directory. EXERCISE 1. NAVIGATE TO THE REPO Open the README.md file with your editor of choice. Make and save changes. 2. MODIFY THE README Run the command: $ git add README.md 3. ADD FILE TO STAGING AREA Run the command: $ git status to ensure your file is actually in the staging 4. RUN GIT STATUS Run the command: $ git commit -m “my commit message” 5. COMMIT YOUR CHANGES
  30. 30. BRANCHES
  31. 31. LINGO MASTER BRANCH The master branch is usually the “production ready” version of your codebase. ! That means that everything compiles, and all your tests pass. This is the version that customers will see - even if the customer is just you. ! There is only one master branch, and generally code is not committed directly to it.
  32. 32. LINGO FEATURE BRANCHES Branches are extremely useful when you want to work on different features without interfering with a working copy of the code. ! When you’re done working on your feature branch, you can merge it back into master. ! If your repository is stored on a remote server, multiple developers can work on the same branch.
  33. 33. BRANCHES VISUALIZED source: http://git-scm.com/about
  34. 34. When you create a new branch, you’re automatically switched to it. ! $ git checkout -b my_branch_name USING BRANCHES CREATE A NEW BRANCH $ git branch -a SEE ALL AVAILABLE BRANCHES $ git checkout my_other_branch CHECKOUT A DIFFERENT BRANCH
  35. 35. MERGING BRANCHES MERGE FEATURE BRANCH INTO MASTER Once you’re satisfied with your feature branch, it’s time to merge it back into master. ! $ git checkout master ! $ git merge my_feature_branch !
  36. 36. EXERCISE CREATE A FEATURE BRANCH
  37. 37. $ git checkout -b my_new_branch EXERCISE 1. CREATE A NEW BRANCH Review the previous exercise if you need hints. 2. COMMIT CHANGES 3. CHECKOUT MASTER $ git checkout master 4. MERGE YOUR BRANCH $ git merge my_new_branch
  38. 38. 1 2 34 CREATE A BRANCH GIT COMMIT COMMIT TO STAGING GIT ADD ADD FILES TO STAGING AREA WRITE CODE HACK HACK HACK 5 GIT PUSH PUSH CHANGES UP TO REPOSITORY GIT CHECKOUT -B GIT WORKFLOW
  39. 39. QUESTIOnS?
  40. 40. COLLABORATING WITH GITHUB
  41. 41. LINGO FORK Forking a repository on github will create a copy of that project in your github account.
  42. 42. A copy that exists in your GitHub account and can be used to submit pull requests (changes) to the maintainers of the project. FORKING VS CLONING FORK A copy that does not exist in your GitHub account, and cannot change the remote repo unless the person who cloned it is added as a collaborator on the project. CLONE
  43. 43. LINGO PUSH/PULL PUSH: Send a copy of the latest committed changes to the remote server. ! PULL: Retrieve a copy of the latest committed changes from the remote server. ! Note: If you’re working on a branch with other people, always run a pull command before getting started.
  44. 44. LINGO PULL REQUEST A pull request is a proposal made by you to a project maintainer asking them to accept your changes to their code base. ! The maintainer can review a diff of the changes you made. 
 They can also leave general and code-line specific comments.
  45. 45. FINAL EXERCISE PULL REQUESTS https://github.com/nnja/gdi-pull-requests
  46. 46. Creating a fork of my repository will copy it over to your github account. FINAL EXERCISE - PT1 1. FORK MY REPOSITORY Go to the github page of your forked copy of gdi-pull-requests. ! Copy the repository URL, clone the project to your local machine. 2. CLONE YOUR FORKED REPOSITORY https://github.com/nnja/gdi-pull-requests git checkout -b <yourname>_branch 3. CREATE A FEATURE BRANCH
  47. 47. Change over to the repository directory. ! Create a file called <yournamehere>.txt. FINAL EXERCISE - PT2 4. CREATE A FILE WITH A FUN FACT ABOUT YOU git add <yourname>.txt git commit -m “here’s a fun fact about me!” 5. ADD, THEN COMMIT YOUR FILE https://github.com/nnja/gdi-pull-requests git push -u origin <yourname>_branch 6. PUSH YOUR BRANCH TO THE REMOTE REPO
  48. 48. FINAL EXERCISE - PT3 7. CREATE A PULL REQUEST https://github.com/nnja/gdi-pull-requests
  49. 49. FIN
  50. 50. RESOURCES ! The entire Pro Git e-book. ! The definitive manual. ! Dense, time consuming, but chock full of information. ! http://git-scm.com/ book/en/v2 ! Short, concise, and visual guides on beginner to advanced github topics. ! https:// guides.github.com/ A 15 minute interactive tutorial. Bonus: Works in your browser, no setup required. ! https://try.github.io/ levels/1/challenges/1 ADDITIONAL TRY GIT PRO GIT GITHUB GUIDES
  51. 51. THANK YOU INTRO TO GIT @nnja girldevelopit.com

×