Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Git & GitHub

Intro to Git & GitHub

This desk was presented as part of a Girl Develop It class given in October 2013.

sarahelizgray

October 12, 2013
Tweet

More Decks by sarahelizgray

Other Decks in Technology

Transcript

  1. • Jana Beck -- TA • Sarah Gray -- Instructor

    • Sarah Johnson -- TA • Selah Lynch -- TA Your Instructors
  2. The Plan • Version Control as a General Concept •

    Git & GitHub Versus Other Version Control Systems • How to Use Github • Git -- The Basic Idiom • Git – Branches • Collaborating with Others -- Break -- • Setup GitHub Account • Setup Git on Your Computer • Free Form Lab Time • Wrap Up
  3. Why Use Version Control? • Made a change to code,

    realised it was a mistake and wanted to go back? • Lost code or had a backup that was too old? • Wanted to see the difference between two versions of your code? • Wanted to prove that a particular change broke or fixed some piece of code? • Wanted to experiment with a new feature without interfering with working code? http://stackoverflow.com/questions/1408450/why-should-i-use-version-control
  4. • If you like the security of having your work

    backed up • If you work with documents that change a lot or have multiple versions (think software,design, and document work) • If you work on a team project • If you apply for engineering/developer positions When should I use it?
  5. Version Control Version Control Software Distributed • Git • Mercurial

    • Bazaar Centralized • Subversion (SVN) • Concurrent Versions System (CVS) Remote Repository Hosting Services • GitHub • BitBucket • Your Own Server • Lots of other services!
  6. Why are you learning git with GitHub? • It's awesome!

    • It’s *the* place for open source projects • http://whygitisbetterthanx.com/
  7. Some of the Criticism • Git is tooo haaarrrrd! ◦

    Yeah, it doesn’t cut you any slack, but the tradeoff is that you get complete control • Everybody can see my stuff on GitHub. ◦ True, but you get to participate in a development community and are on your way to contributing to an open source project. If you want a private repo that only you and collaborators can see, you can pay for one on Github or use a hosting service that offers free private repos like Bitbucket.
  8. Why Commandline? • You will always have the full feature

    set available • You have a built in help function called the MAN page • If you are pair programming with someone else, you won’t need to learn their client.
  9. Basic Ideas for Git and Github • Local Repository ◦

    where code is stored on your local machine • Remote Repository ◦ where code is stored by your hosting service
  10. Let’s make a remote repo • Demo time! ◦ I

    am deliberately not providing instructions here because GitHub changes its interface all the time. My instructions would quickly become outdated. Google is your friend :)
  11. Let’s get that same repo on our local machine •

    Your first git command! ◦ git clone <repo link from github>
  12. Why this order? • git pull ◦ let me see

    what others have done ◦ resolve merge conflicts early • git add <filename> ◦ let me bundle some work together • git commit -m “my comment” ◦ get me make a note about that bundle ◦ -m -- that’s a flag that says use no editor, use the string ◦ MAN page • git push ◦ send it up to the hosting service
  13. Other helpful commands • git status ◦ give me the

    timeline • git log ◦ give me the history • git log --pretty=oneline ◦ give me a simplified log • git stash save “note about what I am saving” ◦ My current work is not ready to be shared but I want to git pull and see what’s going on with the remote repo • git stash pop ◦ give me the last stashed change • git stash list
  14. When to commit • Often ◦ reduces the likelihood of

    merge conflicts ◦ makes it easier to mix and match features ◦ helps with good coding practice -- write a method, write some tests, commit
  15. Sorry Ron . . . If you are writing a

    method that slices, dices, and sautees, you have a problem. Ditto if you have a commit with too much going on.
  16. What if I Want to Experiment? • Branches give you

    an easy way to have two parallel streams of work until you are ready to settle on one solution. • Lets you mix-and-match features from each branch. • Branches are often used for development in a professional environment.
  17. Branch commands • See local and remote branches ◦ git

    branch -a • Get a remote branch onto your local machine ◦ git checkout --track origin/<branch name> • Cut New Branch ◦ Make local branch ▪ git branch <branch name> ◦ Make remote branch ▪ git push -u origin <branch name> • Switch to a Branch ◦ git checkout <branch name>
  18. Criticism • If I commit often and work on a

    branch. It’s harder to mix-and-match code ◦ git squash lets you bundle commits together on branch, then you can git cherry-pick it to master
  19. You’ll Need to Make Some Choices • Two Options: ◦

    git mergetool ◦ use the editor • Commit the merged file
  20. Two Ways to Do This: • Fork and Pull ◦

    contributing to open source projects ◦ using code created by others ◦ http://xkcdgraphs.com/ • Shared Repo ◦ How a professional office would use git ◦ Git Workflow
  21. Adding a Collaborator to Your Repo • Again, no instructions

    for GitHub’s website http://programmerryangosling.tumblr.com/
  22. • Work on your own projects with instructor assistance •

    Practice what’s already happened in Lecture ◦ clone [email protected]:sarahelizgray/reptiles.git • Discover advanced features by playing a game ◦ https://rubygems.org/gems/githug Lab Time
  23. What’s Happened Today: • You know the difference between git

    and other VCS • You know about GitHub and other hosting services • You have git and GitHub ready to go! • You know the basic idiom • You some advanced ideas like branches and git workflow • You know how to call the MAN page • You have a git cheatsheet
  24. Other Resources • Beautiful graphical representation of git features ◦

    http://www.ndpsoftware.com/git-cheatsheet.html • Continue with Githug ◦ https://rubygems.org/gems/githug • A great in-depth guide to git, also a book ◦ http://git-scm.com/book • The Original Git and Github GDI Class Slides ◦ http://teach.github.com/presentations/git-foundations.html • More on Git Workflow ◦ https://www.atlassian.com/git/workflows#!workflow-gitflow • More Silly Ryan Gosling Programming Jokes ◦ http://programmerryangosling.tumblr.com/
  25. Don’t Forget to Evaluate the Course! This is the first

    time this course has been taught at GDI Philly. Your feedback is important! ** url needed here Thank you, Thank you, Thank you for coming!