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

Git, GitHub, & How I work

Git, GitHub, & How I work

A talk I put together for Syracuse dev group (womenincoding.com)

Mike Vormwald

April 12, 2017
Tweet

Other Decks in Programming

Transcript

  1. Who am I? Mike Vormwald - Senior Software Engineer @

    Stitch Fix - Instructor @ StartFastCODE - Organizer @ OpenHack Syracuse - Git / GitHub Enthusiast
  2. Who are you? Say hello 1. What is your name?

    2. A thing you like about the summer? ! ! ☀
  3. Disclaimer Git is a large topic. • There will be

    things we don't cover tonight. I'd love to talk to you afterwards • This is an interactive session... please ask questions as we go
  4. Disclaimer #2 We are covering git on the command line

    You don't have to. You can use an App instead: • git kraken • source tree • github desktop • atom
  5. Tonight's agenda 1. Why do I need git? 2. Cover

    the essential git commands and terms 3. [We handwave away a lot of edge cases / intermediate commands] 4. GitHub! 5. More advanced commands (How Mike works)
  6. Actionable takeaways Tonight's Goal: • Never used git before? You

    see the benefits and feel comfortable using it in your own projects • Used git before? I hope you learn a useful trick or two
  7. 0. Why do I need git? • Git is a

    Version Control System
  8. 0. Why do I need git? • Git is a

    Version Control System • Git exists so you can modify/change/break/improve your code, secure in the knowledge that you can not ruin your work too badly because you created save points along the way.
  9. 0. Why do I need git? • Git is a

    Version Control System • Git exists so you can modify/change/break/improve your code, secure in the knowledge that you can not ruin your work too badly because you created save points along the way • Git allows teams to work together on a common set of files without overwriting each other • Git allows you to see all your past changes and interact with them
  10. 0. Why do I need git? When you're just starting

    out Git can seem like too much of a hassle to be worth using, BUT... • Team Projects may be where Git really shines, but its worth it for solo projects as well (e.g. If computer breaks your code will be safe) • Gives you a skill for working on collaborative projects in the future
  11. git init "Initialize", or put Git in this folder so

    that it keeps track of changes to files in this folder and subfolders git init We now have a new empty Git repository !
  12. git status Show me which files have been changed and

    which ones are ready to be committed. You will use this command A LOT. git status
  13. Terms Working Directory: the directory you’re writing code in Staging

    Area: files are in the staging area if the changes in them will be included in the next save point Repository: everything Git is keeping track of
  14. git add Lets create a new file and add it

    to our repository echo "womenincoding.com" > event.txt git add event.txt Include the changes to this file in the next commit
  15. git add Working Directory: the directory you’re writing code in

    ! Staging Area: files are in the staging area if the changes in them will be included in the next save point Repository: everything Git is keeping track of
  16. git commit Wrap up all these changes from "the staging

    area" and save them together with a short description of the changes git commit -m “Add event description text”
  17. git commit Working Directory: the directory you’re writing code in

    Staging Area: files are in the staging area if the changes in them will be included in the next save point ! Repository: everything Git is keeping track of
  18. git branch What are all my branches? or what are

    all the names of the different versions of my code? git branch
  19. git branch feature-name Make a new branch/version of my code

    with the name feature git branch my-new-branch
  20. git checkout feature-name Move to that branch/version of my code

    so I can make changes to that branch/version of my code git checkout my-new-branch
  21. master branch The name of the branch which should be

    the official, working, well documented, version of my code
  22. git merge Combine the history of two branches so I

    can have the changes from both in one place
  23. Merge conflict Git does not know how to combine two

    histories and needs human assistance • Open the conflicted file • Edit the combined text • Save the file • Commit your changes
  24. On branching & GitHub Flow I generally follow GitHub flow,

    which basically says master branch is ready for production, other branches are for work (works well with teams) https:/ /guides.github.com/introduction/flow/
  25. Remote repository A remote location that you can push your

    commits to GitHub is a popular repository host
  26. git remote add origin address-of- remote Make address-of-remote a new

    place to store my code and call it “origin”
  27. git remote -v To see what remote locations your local

    repo knows about git remote -v origin [email protected]:openhacksyr/openhacksyr.github.io.git (fetch) origin [email protected]:openhacksyr/openhacksyr.github.io.git (push)
  28. git push -u origin master Push my code to the

    location origin points to, on the master branch, and also in the future I will pull code from this same location Terms: • Upstream: where I will pull code from in the future • Origin: where I put backups or share my code
  29. Interacting with a remote • git pull: grab code from

    remote repository • git fetch: grab code from remote repository • git push: save my history and changes in another location
  30. GitHub terms Fork: I want a GitHub repo that looks

    like someone else’s repo Pull Request: I made some changes that I would like you to include in your repository, please accept them git clone: give me the code at this location
  31. #2. Intermediate / advanced git commands AKA Mike handwaves this

    topic away • Try to learn the fundamentals listed above • Learn more advanced commands on a need-to-know basis Google is your friend. These are very common questions
  32. #2. Intermediate / advanced git commands The nice thing about

    git is there is major value added to your life, just by using the basic commands • Commit your changes as you go • Push them to a remote repository • Repeat
  33. #3. GitHub ... lets also handwave past GitHub basics Github

    is a hugely popular git repository hosting service / social network
  34. GitHub We are going to look at a pull request

    I made on OpenHackSyr.com https:/ /github.com/openhacksyr/openhacksyr.github.io/pull/19
  35. This Pull Request ... is silly, BUT: • It only

    solves one thing • It has well written commit messages • Includes checkboxes to indicate progress
  36. Bad commit messages • Provide no context • Tell no

    story • Are bad Identifiable information has been redacted because my friend promises to write better messages in the future
  37. Good commit messages Capitalized, short (50 chars or less) summary

    More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. Encourached by GitHub http:/ /tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
  38. How can we make it better? Whenever creating a Pull

    Request that changes the visible application • Add a screen shot of the visual changes • BONUS POINTS If possible add an animated gif of new behavior (lots of ways to do this. google "licecap")
  39. Last Note on Pull Requests • Small, focused PRs are

    better, and get more helpful feedback • Anything that is merged into master should be immediately deployable
  40. #4. How Mike works Lets live code on OpenHackSyr TODO:

    1. We realize we need to add April's event data 2. Then we should address feedback on Pull Request #19 3. Update the dog gifs in multiple commits 4. Push our commits to the PR
  41. Problem 1/6 When I commit my code, it opens a

    weird editor ("vi") to enter my commit message Solution To encourage better more intentional commit message, lets set editor to nano git config --global core.editor "nano" git commit [Opens nano] control-x y (to save)
  42. Problem 2/6 I want to get to know this repo,

    then add April's event information Solution • git log --oneline -n 5 • git show HEAD • git show HEAD~n • git add • git commit
  43. Problem 3/6 I just commited changes to master !! !

    Solution • git reset --soft HEAD~ • git branch add-april-event • git checkout add-april-event • git add . • git commit
  44. Problem 4a/6 I'm working on multiple features at once, and

    have need to switch back and forth between branches Solution (stash) • git stash • git stash list • git stash show -v • git stash pop
  45. Problem 4b/6 I'm working on multiple features at once, and

    have need to switch back and forth between branches Solution (WIP Commit) • git add . && git commit -m "WIP" • git log --oneline -n 5 • git show HEAD • git reset HEAD~
  46. Problem 5/6 I need to find a string somewhere in

    the codebase Solution git grep -i mike
  47. Problem 6/6 I need to get the dog gif page

    in its current state into a new branch Solution git checkout master git checkout -b a-new-dog-themed-branch git checkout dog-gifs -- top-5-dog-gifs.md
  48. My fav commands • git status • git status, git

    status, git status • git commit --amend to add or rewrite • git add -p • git diff --cached • git commit -v
  49. ~/.gitconfig ... [alias] s = status a = !git add

    . && git status au = !git add -u . && git status aa = !git add . && git add -u . && git status c = commit -v ac = !git add . && git commit acm = !git add . && git commit -m l = log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset' lo = log --oneline ll = log --stat --abbrev-commit d = diff --color-words dc = diff --cached br = branch co = checkout master = checkout master g = grep --break --heading --line-number pf = push --force-with-lease
  50. Summary • Use branches for new work, keep master clean

    • Don't be afraid when commiting/undoing changes on a branch, everything* can be undone • Write nice commit messages, please • Commit your changes in small concise chunks
  51. Teaching references A lot of information in this presentation came

    from these great posts • recompilermag.com/issues/issue-1/how-to-teach-git/ • medium.com/@the_taqquikarim/two-questions-to-consider- before-teaching-git-77f5f7eccaea