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

Git + Github: Unlock this Achievement!

Git + Github: Unlock this Achievement!

Simple introduction to using Git and Github, along with step by step tutorial.

cherimarie

May 01, 2013
Tweet

Other Decks in How-to & DIY

Transcript

  1. Git + Github: Unlock this Achievement! Cheri Allen Github.com/CheriMarie @CheriMAllen

    DinosaurParty.info/gitslides.html
  2. What this Presentation Covers Basics of version control Description of

    Git and Github Basics of command line Downloading, installing, configuring Git The workflow with Git Main Git tools Configuring remote (Github) connections Forking and cloning a repo on Github Contributing changes to a public repo
  3. Version control is the management of changes to files or

    projects. It allows you to easily revert a document back to an earlier state. http://en.wikipedia.org/wiki/Version_control Version Control
  4. Saving files with version names :( Subversion (Svn) * Bazaar

    Mercurial Tower * *offer GUI interfaces http://en.wikipedia.org/wiki/Comparison_of_revision_control_software Other popular version control tools
  5. 1-It's distributed, works great for teams "Distributed revision control (DRCS)

    takes a peer-to-peer approach to version control, as opposed to the client-server approach of centralized systems. Rather than a single, central repository on which clients synchronize, each peer's working copy of the codebase is a bona fide repository. " http://en.wikipedia.org/wiki/Revision_control 2- It's got tons of documentation and support 3- It's open source 4- It's fast 5- It doesn't require any network connection Why Git is the most popular
  6. Tracks the changes in files- not the files themselves! Keeps

    full history of a document. Once changes are committed, it is not possible to change the old version. http://en.wikipedia.org/wiki/Git_(software) What exactly does Git do?
  7. It's a hosting site for software development projects that use

    Git. It has paid and free memberships. Free ones require that you only have open source (visible to everyone) projects. It offers a variety of social networking functions, like following and RSS feeds, based around repositories. http://en.wikipedia.org/wiki/Github What does Github do?
  8. Command line entries: indented pink text Should be replaced with

    real information: [text in brackets] Output expected in the command line: indented purple text Practice activity- work along! white background Using these Slides
  9. . the directory you are currently in .. the directory

    one level up ~ your home directory cd [place] change directory to [place] clear clear terminal screen diff [name1] [name2] display differences between files help lists possible commands ls lists contents of present directory mkdir makes a directory (folder) pwd lists present working directory rm [file] removes (deletes) [file] touch [name] creates a file called [name] Bash command line basics
  10. Downloads available from: git-scm.com/downloads Welcome to Git

  11. Go here: https://help.github.com/articles/set- up-git Choose your OS, then follow instructions.

    Skip credential helper for right now. Windows: Please expand the "Not Sure What to Pick for Each Screen?" and follow recommendations. Installing Git
  12. git config --global user.email "[email]" git config --global user.name "[name]"

    Email should match one on your Github account. Name will attach to commits- be professional. Confirm : git config --global user.email git config --global user.name Or view config file at ~/.gitconfig http://git-scm.com/docs/git-config Configure Your Git Account at the Command Line
  13. command git init do some stuff git add [stuff] git

    commit -m " " git status The Git Flow what it does initializes a repo stages changes commits changes what's up, git? This is the general workflow in Git.
  14. Git Flow in Action

  15. Git Practice On the command line, navigate to a reasonable

    place to make a new directory. Documents or Desktop, perhaps. Then, make the directory. cd [~/Documents] mkdir DoingGitStuff Navigate into the new directory cd DoingGitStuff Initialize it as a Git repository git init Create a file touch coolfile.txt See what's up with Git git status Oh, you have an untracked file! Let's track it. git add coolfile.txt And save these changes git commit -m "Add new file" Sweet!
  16. Every commit must have a message. Make it: Precise and

    polite Short : 50 characters or less Begin with active, present-tense verb GOOD: "Fix the js bug causing login errors" "Update README.md" "Add support for packager to build installers" Best Practices: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html Commit Messages
  17. BAD: "Added some stuff to menu." "Undid Bob's stupid mistake"

    "so many php errors" "went and fixed the pager, added some new stuff to the headings, put that photo of a bulldog in there" http://www.commitlogsfromlastnight.com/ Commit Messages
  18. • All repos have Master branch. • Use feature branches,

    with appropriate names, to work on features. • Merge successful feature branches back into Master. • Remote and local branches must be created independently. Give them the same names! • You work on correct branch locally, but remote only matters when you're pushing. • Merging branches is potentially frustrating. Branches
  19. git branch *master git branch feature git checkout feature git

    branch master *feature do some work git push origin feature Branch Creation + Movement what branch am I on? create a feature branch go to feature branch what branch am I on? ... push to remote feature branch
  20. Branch Practice From inside your DoingGitStuff directory, see what branches

    are available git branch Ah, you only have a master, which was created automatically at the time of your first commit. Let's assume you're about to try a cool new thing in your code that may not work. You should put it in its own branch until it's complete so the master branch keeps working well. Create a new branch called feature. git branch feature Did it work? Let's see what branches are available now. git branch Now you have two branches listed, right? Good. Let's switch to working in the feature branch. git checkout feature Cool! Now do your risky work (or just make changes to coolfile.txt). We'll later merge this branch back into master.
  21. checkout lets you check stuff out! It takes you/HEAD to

    the place you specify, whether that's a commit or a branch (which is shorthand for "the last commit in this particular branch") . Example: git checkout feature git checkout 50edd9bc416048059ef166d git checkout
  22. When a feature is complete, or working well, merge the

    feature branch back into Master. You must be on master to do the merge. git checkout master git merge feature -m "Implement new feature" http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging Merging
  23. Merge Practice While on feature branch, edit coolfile.txt however you

    like and save the file. Add and commit the change git add coolfile.txt git commit -m "Add excellent data to coolfile" Check status git status # On branch feature nothing to commit (working directory clean) Looks good! Now go back to master branch git checkout master And merge the feature branch into master git merge feature Updating 4308a22..338be7b Fast-forward coolfile.txt | 1 + 1 file changed, 1 insertion(+) Cool!
  24. Merge conflicts usually arise when multiple people commit changes to

    the same part of a file. Fix by looking at both versions of the file and deleting one set of conflicting changes. Open the file with a text editor or git mergetool http://stackoverflow.com/questions/161813/how-do-i-fix-merge-conflicts-in-git Merge Hell
  25. Get a list of past commits by running: git log

    Past commits look like this: commit 50edd9bc72e5416048059ef166d554e3cd85b4dd Author: cherimarie <[email protected]> Date: Sun Feb 24 18:18:54 2013 -0800 Copy the SHA (secure hash algorithm) of the commit you'd like to roll back to and checkout: git checkout [50edd9bc72e5416048059ef166d554e3cd85b4dd] Rolling Back Repo to Earlier State
  26. .gitignore- file in repo root, use to hide sensitive or

    meaningless information from git git cherrypick- transfer only some commits to new branch git rebase- powerful tool, can change commit history, potential for mayhem http://git-scm.com/docs Git Extras
  27. Now you can create and use local repositories to track

    changes in files on your machine. You can work in different branches to experiment safely with ideas that may break your project. You can merge branches together when they're good and roll back commits when something goes badly. Summary
  28. Sign up or in now: github.com Welcome to Github

  29. Github.com/Explore See what's new and popular right now. Find a

    contributor who seems awesome, Follow them. Ask the person next to you for their Github address. Go visit their page. Maybe follow them, too! Come visit me at github. com/cherimarie and we can be friends. Be Social
  30. All the Octocats: http://octodex.github.com/ This is Octocat, Github's Mascot

  31. 1- On Github.com, create a new repository with same name

    as local one (DoingGitStuff) 2- Copy HTTPS address of new repo 3- In Terminal: cd DoingGitStuff git remote add origin [pasted address] git remote git push origin master *origin is what you are naming connection *master is the remote branch you're sending to Configure Remote Connections
  32. HTTPS: Good for insecure computers. You enter your Github name

    and password every time you push or pull, unless you have a credential helper. Very easy to set up. SSH: Good for secure computers. You generate a SSH key locally that identifies your machine to Github. Follow github tutorial to set up, not terribly hard. SSH or HTTPS Remote?
  33. 1- Find a cool repo on Github 2- Fork the

    repo 3- Clone the repo so it's available locally 4- Do some work! Fix bugs, add features. 5- Add and commit work to your local repo 6- Push work back to your forked repo 7- Send a pull request to original owner 8- Add "Contribute to open source projects" to your resume Working on Open Source Projects
  34. Forking a Repo Demo: Part 1 1- Go to: Github.com/cherimarie/GitResources

    2- Fork by pushing the "fork" button 3- Copy HTTPS address of your fork of repo 4-Clone repo to local machine git clone [pasted address] This copies the whole directory to your local machine, initializes it as a repo, and builds in the remote connection! 5- Open GitResources.docx in a text editor, add something to it, save
  35. Forking a Repo Demo: Part 2 6- Commit your changes

    to local repo git add . git commit -m "[comment]" 7- Push to your Github repo git push origin master 8- Send pull request to CheriMarie From your repo's page on Github, "Pull Request" button, fill out title and description, "Send" 9- Win!
  36. You can now create repos on Github and link them

    to your local ones so you can push and pull changes. You know how to fork and clone cool repos so you can work on open source projects, plus send pull requests back to the original authors to have your changes incorporated into the main project. Summary
  37. Git and Github are powerful tools, and as such take

    time and practice to master. There are ample resources available to help you out- take advantage of them. When Git is supplanted by the next hot thing, be ready to learn an entirely new system! I'm Cheri Allen, @CheriMAllen on Twitter. I'd love to hear your feedback about this slidedeck and what your favorite octocat is! Wrap Up