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

Git Workshop

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Git Workshop

Git tutorial and workshop for Systers organization at University of Tennessee

Avatar for christinejones

christinejones

November 18, 2015
Tweet

More Decks by christinejones

Other Decks in Technology

Transcript

  1. • Food, Home, and Travel • Television & Digital •

    Networks Available World Wide • 60 Million Unique Visitors Per Month • Internationally Headquartered in Knoxville, TN About Scripps Networks Interactive
  2. Why do I care? • Have you ever lost your

    work? • Have you ever broken something and wanted to go back to an earlier version of your program? • Have you ever worked on a project with someone else? • Do you want a job?
  3. Version Control Benefits 1. Collaboration 2. Archiving 3. Roll back

    4. Experimentation 5. Maintenance 6. Comparing versions of code 7. Code history 8. Accountability 9. Backup
  4. First Generation - 1972 Source Code Control System (SCCS) Revision

    Control System (RCS) Quick History of Version Control Networking Operations Concurrency None Single File Pessimistic Locking
  5. Second Generation - 1986 Concurrent Versioning System (CVS), Subversion (SVN),

    Microsoft Visual SourceSafe (VSS), Perforce, Microsoft Team Foundation Server (TFS), IBM ClearCase Quick History of Version Control Networking Operations Concurrency Centralized Multi File Optimistic/Merge
  6. Third Generation - 2000 BitKeeper, Bazaar, Mercurial (hg), Git Quick

    History of Version Control Networking Operations Concurrency Distributed Changesets Merge
  7. Terminology Repository - where files and related data are stored

    Branch - copy of project where changes can be made Trunk - base of a development project; “main” branch of a project Merge - operation where changes are applied from branch A to branch B Commit - save changes to a branch Push - send changes to the repository Pull - receive/fetch changes from the repository Conflict - situation where two branches have updated the same files, requires user to determine which changes to keep
  8. What is Git? Distributed version control. Free and Open Source.

    Probably available on your operating system. Originally built by Linus Torvalds while working on the Linux kernel. He was using BitKeeper but the copyright holder was going to start charging him. So he built his own system. Extremely popular for Open Source projects, and enterprise projects. Source: xkcd.com
  9. Git Hosting Services Provides a “centralized” place to host your

    repository. Enables collaboration and Social Coding. Web interface into your repository. Issue Tracking. Integrated Wiki. Gives your project a shareable URL.
  10. Basic Commands help config create repo - init add/rm commit

    create/merge branch checkout / clone pull push log stash
  11. Git Workflow A Very Simple Git Workflow 1. Create a

    repository. 2. Create or modify files. 3. Stage changes to staging area. 4. Commit changes. 5. Repeat steps 2 - 4 as your project grows.
  12. Getting Started With Git git config • git config --global

    user.name “My Name” • git config --global user.email [email protected] git init • Create a new directory and “cd” into that directory • git init
  13. You’ve Got a Repository, Now What? Adding to a repository

    • Create a file or directory in your repository (README.md) • git add <name of file/directory just created> Removing from a repository • git rm <name of file/directory no longer needed> • Remove the file or directory that you just removed from the repository. You must remember to re-add files that you have changed to the repository.
  14. Saving Your Changes Time to save the changes: • git

    commit -m “A meaningful message describing the changes.” A best practice of commit is to speak in the present tense. • git commit -m “Add README.md.”
  15. Time to Branch Create your own copy of the repository:

    • git branch <my_branch_name> Running git branch by itself will list the branches of the repository stored locally. Switching between branches: • git checkout <my_branch_name>
  16. Merging Branches To synchronize two branches, use the merge command:

    • If you want to merge the master branch into your current branch: ◦ git merge master • Merging your branch back into master ◦ git branch master ◦ git merge <my_branch_name> • Make sure that the branch being merged into is checked out. It is a best practice to merge master back into the branch being worked frequently.
  17. Let’s Add Other People to the Repository A More Complicated

    Git Workflow: 1. Clone a repository from a remote site. 2. Create a branch to work on your own copy of the code. 3. Make changes to the code base. 4. Merge the trunk (master) into your branch 5. Test the code base to verify your work. 6. Repeat steps 3 through 5 until you feel that your work is complete. 7. Merge your branch back into master.
  18. Working With a Remote Repository A remote repository is cloned

    to your local environment: • git clone https://github.com/SNIDemo/ExampleRepo.git • this command will copy the remote repository down and checkout the master branch Changes to repository are updated with the push and pull commands. • git status - checks the remote repository for changes • git pull - copies changes down from remote repository • git push - uploads local changes to the remote repository
  19. Two More Git Commands Worth Mentioning git log • presents

    a list of changes • allows for examination of the history of the repository git stash • puts your changes in a safe place if you need to switch branches • usually used in collaborative environments