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

Intro to Git & GitHub

Intro to Git & GitHub

This deck was used for Intro to Git & GitHub, a Girl Develop It Philly talk given October 12, 2013.

sarahelizgray

October 12, 2013
Tweet

More Decks by sarahelizgray

Other Decks in Technology

Transcript

  1. 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 • Lab Time • Wrap Up
  2. 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
  3. When should I use it? • If you like the

    security of having your work backed up • If you work with documents that change a lot or have multiple versions • If you work on a team project • If you apply for engineering/developer positions
  4. 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!
  5. Why are you learning git with GitHub? • Git is

    fast and full featured. • Github is *the* place for open source projects • http://whygitisbetterthanx.com/
  6. 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.
  7. Why Command Line? • You will always have the full

    feature set available • You have a built in help function called the MAN page • If you are working with someone else, you won’t need to learn their client
  8. A Quick Sidenote About Tools Used During the Lecture •

    I’ll be using sublime text to manage files ◦ http://www.sublimetext.com/2 • I’ll be using a bash terminal most of the time • I’ll show you ohmyzsh -- mac only :( ◦ https://github.com/robbyrussell/oh-my-zsh ◦ http://zsh-nt.sourceforge.net/ (windows?)
  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. A Quick Tour of GitHub • See repos • See

    commit stream • A quick aside: gists & github.io • Let’s make a repo!
  12. Let’s Get That Same Repo on Our Local Machine •

    Your first git command! ◦ git clone <repo link from github>
  13. 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” ◦ let 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
  14. Other helpful commands • git status ◦ show me what’s

    happening right now • git log ◦ show me the local timeline • git log --pretty=oneline ◦ show me a simplified version of log
  15. The Stash • git stash save “note about what I

    am saving” ◦ My current work is not ready to be committed but I want to interact with the remote repo • git stash pop ◦ apply the last stashed change • git stash list ◦ show me all stashed changes
  16. Let’s Play with Reset and Work with the Timeline git

    log git reset <SHA/Commit ID from log>
  17. When to commit • Often ◦ reduces the likelihood of

    merge conflicts ◦ makes it easier to have a fine-grained timeline to play with ◦ helps with good coding practice -- write a method, write some tests, commit
  18. 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.
  19. What if I Want to Experiment? • Lets you work

    on an aspect of a project without disrupting the work of others. • Gives 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.
  20. Branch commands • What branch am I in? ◦ git

    branch • See local and remote branches ◦ git branch -a • Get a remote branch onto your local machine ◦ git checkout --track origin/<branch name> • Cut a 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>
  21. Merge If you want to merge all of your commits

    from branch to master: git checkout master git merge <branch name> It will interleave the commit history from branch with the commit history from master -- so it becomes a complete timeline!
  22. You’ll Need to Make Some Choices • Two Options: ◦

    git mergetool ◦ use the editor • Commit the merged file
  23. Criticism • If I commit often and work on a

    branch. It’s harder to mix-and-match code ◦ git’s squash feature (git rebase -i <SHA/Commit ID from log>) lets you bundle commits together on branch, then you can git cherry-pick it to master http://stackoverflow.com/questions/5189560/how-can-i-squash-my-last-x-commits-together-using-git
  24. 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 likely use git ◦ Git Workflow
  25. The Difference Between Fork and Clone Fork & Pull/Fork &

    Clone -- a copy that exists in your GitHub account can be used submit pull requests/submit changes without a relationship to the project. Clone/ Shared Repo -- a copy that does not exist in your GitHub account and cannot change the remote repo unless the cloner is added as a collaborator on the project.
  26. Adding a Collaborator to Your Repo • Again, no instructions

    for GitHub’s website http://programmerryangosling.tumblr.com/
  27. Play Githug or Work on a Personal Project • Work

    on your own projects in git with instructor assistance • Discover advanced features by playing a game
  28. 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 know some advanced ideas like branches and git workflow • You know how to call the MAN page • You have a git cheat sheet
  29. 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 • Student/Educator? -- you may need a private account ◦ https://github.com/edu • More silly Ryan Gosling programming jokes ◦ http://programmerryangosling.tumblr.com/
  30. Don’t Forget to Evaluate the Course! This is the first

    time this course has been taught at GDI Philly. Your feedback is important! http://bit.ly/GRs1EC Thank you, Thank you, Thank you for coming!