Session 3 More Git and Intro to GitHub

Goals

By the end of this session, you will be able to:
  • navigate important parts of a GitHub repository
  • design methods that use/modify attributes
  • create your own repository on GitHub
  • push local changes to a remote
  • fork and clone an existing repository

Agenda

Materials

  • Notebook
  • Writing instrument
  • Laptop
  • Headphones & mic

Housekeeping, Wins/Follow-Ups, and Goals

Wins

  • Strong understanding of terminal and commands - 4.5+ Average Score
  • Most common answer to git question: “I can name the steps of the git workflow and can put them in practice (using a reference).”
  • This is totally acceptable, and we use references as programmers on the job all the time. The best programmers google, reference, and implement more often and at a faster pace.
  • Great job posting in the channel and finding typos

Follow-Ups

  • Asking questions is a skill
    • shout out to Quinn and Ryan for asking really good questions in slack
    • also thanks to all of y’all answering questions!
    • how to post code/command snippets in slack
    • pinned items
  • Capstone progress (should be on day 4/5 by now)

Today’s Goals

(See above)

Warm Up

Last week, we briefly talked about keyboard shortcuts in the Mac environment and in Chrome. You should also learn and practice these terminal and atom shortcuts.

Try it: Practicing Shortcuts

Terminal

Use these shortcuts to quickly move around within your terminal.

  • Cycle through past commands
    up arrow
  • See all commands previously typed
    type "history" in the command prompt
  • Clear Command Line
    control + u
  • Clear Terminal Window
    command + k
  • Open New Tab
    command + t
  • Cycle Through Terminal Tabs
    control + tab
  • Goto Beginning of Line
    control + a
  • Goto End of Line
    control + e
  • Fast Moving Cursor Through Command Line Text
    Right: option + right-arrow
    Left: option + left-arrow
  • Stop Any Terminal Process

    Stuck? Not sure what's going on with your Terminal? This is the command to use.

    control + c
  • Atom

    Use these shortcuts to quickly move around within your text editor.

  • File Finder
    command + t or command + p
  • Toggle File Tree
    command + \
  • Highlight Current Line(s)
    command + l
  • Highlight Current Word
    command + d
  • Find in page
    command + f
  • Find and replace in project (use with caution)
    command + shift + f
  • Split panes
    command + k + arrow(choose direction)
  • Intros, Review, and Icebreaker

    Person with the lightest color shirt speaks first.

    1. Introduce yourself: name, pronouns

    2. Share: Do you dress up for halloween? What is your favorite costume you've worn or seen?

    3. Accountability review: how are you progressing toward mastery of your focus skills?

    Have extra time? Share helpful resources you've come across.

    Class and Method Review

    Try It: Methods

    Post one sentence in the chat about a class using this structure:

    Each _______ (class) can ___________, __________, and ___________.

    Example: Each bank account (class) can have money deposited, can have money withdrawn, can be opened, can be closed, and can change ownership (methods).

    Method and Attribute Interaction

    Like we talked about during session 2, a method of a class define behavior/actions. Methods are generally verbs (action words or very short action phrases). Methods generally answer the questions “What things can instances of this specific class do?” or “What can be done to instances of this specific class?”

    Most of the time, a method will either use or change an attribute of an object. For example, look at the attributes of the class Bank Account below:

    Class: Bank Account
    
    Attributes (____ has a/an _____):
    owner_name
    balance
    overdraft_fee
    

    Here are some Bank Account methods and the attributes that would be used/changed. Notice that these are all verbs or action phrases.

    Methods:
    change_owner (modifies the owner_name attribute)
    deposit (modifies the balance attribute)
    withdraw (modifies the balance attribute AND uses the over_draft fee if the balance drops below $0)
    display_account_info (uses the owner_name and balance attributes)
    

    Example #2

    Look at the Car class and its attributes below:

    Class: Car
    
    Attributes (____ has a/an _____):
    amount_of_gas (integer)
    paint_color (string)
    number_of_carseats (integer)
    engine_status (boolean)
    passengers (array)
    last_oil_change (datetime)
    

    Try It: Methods with Attributes

    Post two sentences in the chat about the Car class using this structure:

    The ____________ method [modifies/uses] the _____________ attribute.

    Example: The start_engine method modifies the engine_on attribute.

    Make sure that your method names are verbs or action phrases.

    Git Review

    Let’s talk once more about this Git diagram.

    Git Workflow Diagram Source: https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository

    We’ll start by repeating the group git exercise from Tuesday’s session. This may seem repetative, but each time you practice, you’ll gain muscle memory and procedural understanding.

    Today’s driver will be the person who was born closest to the state of Indiana. Everyone else will be navigators. Driver: remember not to type anything that has not yet been brought up by a navigator and discussed in the group.

    The driver will be the person typing the commands, but the navigators should be the ones who brainstorm what comes next or what to type. In addition to naming the steps, discuss why you are doing each step, or what exactly is taking place in each step.

    Remember: If you feel comfortable with git, your job is to hone your explanation and communication skills. Many companies in the industry that place far more weight on these professional skills than on being a technical superstar.

    Try It: Git Review

    As you and your group walk through the git review below, it might be a good idea to have Session 2's Git Notes open.

    1. Before we do this, make sure the driver is in the home directory by typing cd
    2. Create a new directory called session_3_git_practice. Inside of that directory, create three files called coding_languages.txt,programming_terms.txt, andgit_terms.txt.
    3. Tell git to start watching the session_3_git_practice directory.
    4. Before you check the status, predict what it will say. Then, check the current status.
    5. Add coding_languages.txt to the staging area.
    6. Make your first commit in this directory. What should the commit message here be?
    7. Before you check the status, predict what it will say. Then, check the current status.
    8. Add programming_terms.txt andgit_terms.txt to the staging area.
    9. Make your second commit in this directory. This commit should include both files from the previous step. What should the commit message here be? Why? What conventions have we talked about?
    10. Use the atom to add the names of two separate coding languages to coding_languages.txt. You may Google "programming languages" if you can't think of any.
    11. Before you check the status, predict what it will say. Then, check the current status.
    12. Before you check the difference between your last commit and what the file looks like now, predict what it will say. Then, check the diff.
    13. Add the changes to the staging area.
    14. Before you check the status, predict what it will say. Then, check the current status.
    15. Commit the changes using a properly formatted commit message.
    16. Before you check the status, predict what it will say. Then, check the current status.
    17. Repeat steps 10-16 again, adding the names of some programming terms and some git terms to the respective files.
    18. Add and commit the changes to these two files together with a properly formatted commit message.

    Finished before time is up? Repeat, but choose a different driver this time.

    GitHub

    Git is not the same as GitHub. They work together, but they are separate tools. Git allows us to track versions of our work on our local computers. GitHub is an online git repository hosting service. A repository (or repo) is, at it’s core, a place where your work and commits are stored.

    Other alternatives to GitHub include GitLab and BitBucket, among others. GitHub (and these other services) also makes it easy for teams that use git to collaborate on the same codebase.

    During Mod 0, we will not be exploring the collabortive functionality of GitHub. We’re going to stick to learning the basic functionality of GitHub.

    Let’s first discuss this diagram:

    Github Diagram

    Source: http://frontend.turing.io/assets/images/lessons/git/github-diagrams.002.jpeg

    origin: refers to the URL where the code is hosted on GitHub. Each repository has its own origin (own URL).

    git pull: means download all of the changes and updates on the remote GitHub repo that I don’t currently have on my local repo. You would use git pull after a teammate makes a change to the code, and you want to bring those changes into your own code.

    git push: this is how you share/upload the changes you made to your local repository on GitHub.

    This diagram shows how GitHub can be used as a collaboration tool:

    Collaborative Github Diagram

    Source: https://www.quora.com/What-is-git-and-repository

    Let’s take a look at an example of a repo on GitHub: FreeCodeCamp

    Try It: Exploring GitHub Repositories

    In your breakout group, choose one of the repositories listed at the bottom of this "Try It" section. Take a few minutes to explore the following questions and be ready to report back to your group:

    1. What is this project about?
    2. How many commits have been made in the repository?
    3. Approximately how often are changes made to this repository? How do you know?
    4. Who is the top contributor?
    5. How many people have contributed to the repository?
    6. How many people are watching the repository? What does this mean?
    7. How many issues are open? Can you decipher what problems any of the issues are reporting? Is there any discussion happening on the issues?
    8. How many open pull requests exist? What was the date of the most recent pull request?
    9. Is there active commenting on the pull requests? Can you decipher what people are discussing?
    10. What other things do you see on the repository? Can you google these things to find out what they are?
    11. Done before time is up? Pick a second repository to explore.

    Options:


    BREAK

    Turn off your mics and videos and walk away from the computer. Stand up, stretch, drink water. Do a few sit-ups, squats, push-ups, jumping jacks, arm circles, stress ball squeezes, or whatever else moves your body.


    Creating a Remote Repo on GitHub

    Watch and take notes while we walk through how to add a remote to your local repository. This assumes we already have a repository initialized with git locally.

    1. Visit github.com/your_username
    2. Click the plus button in the upper-right corner of GitHub and select “New Repository” from the dropdown.
    3. Give your repository a name, and dont worry about adjusting any of the other settings for now.
    4. Scroll down and click “Create Repository”
    5. Scroll to …or push an existing repository from the command line
    6. Paste the lines listed, one at a time, in your terminal. Make sure to follow instructions for SSH
    7. Refresh Github. Tada! Your project is there.

    Try It: Adding a Remote

    1. Create a new repository on GitHub called git_homework.

    2. In your terminal, navigate to your git_homework directory from session 2's homework. If for some reason you don't have this directory then use the mkdir command to create git_homework. Then use touch to create a file calledsample_file.txt. Then run git init. Only do this if you don't already have a git_homework repo.

    3. Add the remote to your local repository, then push your changes to GitHub.

    Making Additional Changes and Pushing to GitHub

    Open up Atom. Use the keyboard shortcut command + o to search for your git_homework project.

    Watch and take notes while we walk through how to continue making changes and pushing those changes to GitHub.

    Try It: Full Git Workflow

    In your breakout rooms, everyone will complete the steps below synchronously, but on your own projects. Use each other as resources and sounding boards. Don't hesitate to click "share screen" if there's something you want your team to look at!

    If you get really stuck, you can click "ask for help" and we'll pop into your room.

    • Add a few new quotes to your quotes.txt file.
    • Save your file using the shortcut command + s.
    • Go back to your terminal.
    • Use commands to add and commit your new changes. Be sure to use git status to check your status, and make sure your commit message is properly formatted.
    • Push your new changes to GitHub.
    • Refresh the page to make sure the new changes appear.
    • Repeat the above steps, but this time, remove one of the quotes from your quotes.txt document, then add, commit, and push your changes.

    Finished? Get to know your breakout room classmates better: What are they trying to get better at in life? What book would the recommend that everyone read at least once in life?

    Forking

    What is Forking?

    Forking allows you to copy someone else’s project while still keeping a reference to the original. To fork an existing project, you just click the fork button, which will make a copy of all of the code and directory structure to your own GitHub account.

    You can tell if something is a fork because it will say “forked from [original repo name]” underneath the title.

    Once you’ve forked a repo, click the green “Clone” button to get the URL to clone.

    git clone <insert URL here>
    

    If you fork, clone, make changes, and push to origin, it will work because it’s pushing to your forked origin (YOUR account), not the original repository (ORIGINAL CREATOR’s account). To push those changes:

    git push
    

    OR

    git push origin master
    

    (In our case today, both commands will do the same thing)

    Things to Note: Cloning with Git

    • Never clone a remote repository within a preexisting Git repository. If you watched the video for modifying your .bash_profile, then you will see [master] if you're already in a git repository.
    • After cloning a repository, remember to cd into the directory you just cloned to your machine before running commands. If you cannot remember what the directory is called then runls after cloning to see the contents of your current directory.
    • There is no need to run git init within a repository that you cloned down to your local machine. Remote repositories that you clone to your local machine have already been initialized by git. You only ever need to run git init when you've created a repository locally from scratch. If you mess this one up, it's not going to cause any problems; it's just unnecessary.
    • Don't use "Initial commit" as your commit message for a cloned repository. Whoever made the repository already did that. You only need "Initial commit" when you make a new repository for yourself.

    Try It: Forking

    1. Fork the Best Animals repository.
    2. Clone your fork using your terminal.
    3. Open up the project in your text editor (atom).
    4. Add a few animals to the mammals.txt file.
    5. Add and commit your changes.
    6. Push your changes to the origin (which is your fork).
    7. Done? Repeat steps 4-6 with another animal file.

    Homework and GitHub Projects

    Find the homework in your Mod 0 Project Board. Contact David or Tim if you’re stuck.