Git101

1,720 views

Published on

Intro to Git slide deck.

Covers initial setup, git init, git add, git diff, git commit, pushing and pulling to repo on Github.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,720
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
36
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • This presentation will cover the basics of the Git Workflow and how it works.
  • The working directory is where you make changes to your files. By staging files to the staging area, you add them to the list of what will be committed next Committing the staged files adds those files (and their contents) to the Git Repo
  • We’ll be using GitHub as a remote repository for our project. Go to this URL to sign up for an account.
  • Generate a local SSH key for use with Github. You can use the default file provided, or give your own path to a key file.
  • Copy and paste the contents of ~/.ssh/your-key.pub into the Key box
  • The bottom commit loop happens frequently. Pushing the the remote happens “occasionally”
  • You commit a change and push to your public repo Bob can then “pull” your change to his repo
  • Bob commits a change and pushes to your public repo You can then “pull” his change to your local repo
  • Git101

    1. 1. Git and GitHub.com
    2. 2. Git 101 <ul><li>Git is a distributed revision control system </li></ul><ul><li>Keeps track of changes made to one or more files over time </li></ul><ul><li>Shows log messages of what changed and why </li></ul><ul><li>Allows developers to share their changes easily </li></ul>
    3. 3. Git Project Sections Source: http://progit.org/book/ch1-3.html
    4. 4. Git workflow Modify Files Stage Files Commit Files
    5. 5. Installing Git <ul><li>Covered in detail at http://progit.org/book/ch1-4.html </li></ul>
    6. 6. Initial Setup <ul><li>git config --global user.name “John Doe” </li></ul><ul><li>git config --global user.email [email_address] </li></ul><ul><li>git config --global core.editor emacs </li></ul><ul><ul><li>By default, it uses GIT_EDITOR, VISUAL or EDITOR Environment variables </li></ul></ul><ul><ul><li>Other editors are vi, mate -m, nano, etc </li></ul></ul><ul><li>git config --list </li></ul><ul><ul><li>Shows your git settings </li></ul></ul><ul><li>See http://progit.org/book/ch1-5.html for more </li></ul>
    7. 7. Getting help <ul><li>Most Git commands have help available </li></ul><ul><li>git help commit </li></ul><ul><li>git help branch </li></ul><ul><li>git help tag </li></ul>
    8. 8. Getting started with Git <ul><li>mkdir project_name </li></ul><ul><li>cd project_name </li></ul><ul><li>git init </li></ul><ul><li>echo “Hello” >> README </li></ul><ul><li>git add README </li></ul><ul><li>git commit -m ‘Initial commit’ </li></ul>
    9. 9. Getting started Lab <ul><li>Create a new directory </li></ul><ul><li>Initialize git </li></ul><ul><li>Create/Edit a file </li></ul><ul><li>Add/Stage that file </li></ul><ul><li>Commit the stage to your local repo </li></ul><ul><li>Repeat </li></ul>
    10. 10. Working with remote repos Public Repo Located on Server (Github) Private Repo Located on your local machine git pull git push
    11. 11. Signup with Github <ul><li>https: //github .com/signup/free </li></ul><ul><ul><li>You can skip SSH Public Key, we’ll come back to it </li></ul></ul>
    12. 12. Setup SSH Keys <ul><li>ssh-keygen -d </li></ul>
    13. 13. Setup local SSH config <ul><li>If you don’t use your “default” ssh key for GitHub, you need to tell SSH to use your Github key </li></ul>
    14. 14. Add SSH Key to GitHub <ul><li>https://github.com/account </li></ul>
    15. 15. Create my_project repo (on Github.com) <ul><li>https://github.com/ </li></ul>
    16. 16. Add your pair to my_project repo (on Github.com) <ul><li>Click the Edit button or go to https://github.com/your-user-name/my_project/edit </li></ul>We’ll use this later
    17. 17. Add remote repo to your local repo <ul><li>cd my_project </li></ul><ul><li>git remote add origin git@github.com:your-user-name/my_project.git </li></ul><ul><li>git push origin master </li></ul><ul><ul><li>“ origin” is configurable name </li></ul></ul><ul><ul><li>“ origin” is convention for GitHub </li></ul></ul><ul><li>View changes at http://github.com/your-user-name/my_project </li></ul>
    18. 18. Remote repos process Public Repo Located on Server (Github) Private Repo Located on your local machine git push Make file changes Stage Changes Commit Changes git add filename git commit -m ‘…’ vi filename
    19. 19. Commit changes and push to remote repo <ul><li>cd my_project </li></ul><ul><li>echo “bye” >> README </li></ul><ul><li>git add README </li></ul><ul><li>git commit -m ‘Added bye to README’ </li></ul><ul><li>git push origin master </li></ul><ul><li>OR </li></ul><ul><li>git push </li></ul><ul><li>View changes at http://github.com/your-user-name/my_project </li></ul>
    20. 20. Lab with remote repos (on Github.com) <ul><li>Modify file locally </li></ul><ul><li>Add/Stage that file to the commit </li></ul><ul><li>Commit your changes </li></ul><ul><li>Push those changes to GitHub </li></ul>
    21. 21. Remote repos process (multiple committers) Public Repo Located on Server (Github) Private Repo Located on your local machine 1) git push Make file changes Stage Changes Commit Changes git add filename git commit -m ‘…’ vi filename Bob’s Private Repo Located on Bob’s local machine 2) git pull
    22. 22. Remote repos process (multiple committers) Public Repo Located on Server (Github) Private Repo Located on your local machine 2) git pull Bob’s Private Repo Located on Bob’s local machine Make file changes Stage Changes Commit Changes git add filename git commit -m ‘…’ vi filename 1) git push
    23. 23. Pull commits from remote repo <ul><li>cd my_project </li></ul><ul><li>git pull origin master </li></ul><ul><li>OR </li></ul><ul><li>git pull </li></ul>
    24. 24. Lab with remote repos (on Github.com) <ul><li>User A </li></ul><ul><li>Modify file locally </li></ul><ul><li>Add/Stage that file to the commit </li></ul><ul><li>Commit your changes </li></ul><ul><li>Push those changes to GitHub </li></ul><ul><li>User B </li></ul><ul><li>Pull those changes from GitHub </li></ul>

    ×