Skip to content

Latest commit

 

History

History
120 lines (83 loc) · 2.8 KB

05-commandline-git-practice.md

File metadata and controls

120 lines (83 loc) · 2.8 KB

Git from the Command Line

Let's practice using Git from the command line.

❇️ Example: fruit-basket

  1. Create 🍒🍎🍌🍇🍑🍉🍍 basket

    cd ~/Development/
    mkdir fruit-basket
    cd fruit-basket
    
    echo "i am cherry" > cherries.txt
    echo "i am a strawberry" > strawberries.txt
    echo "i am a watermelon" > watermelons.txt
    
  2. Initialize repository

    git init
    
    git status
    git log
    
  3. Add the fruits to the staging area.

    git add cherries.txt
    git add strawberries.txt
    git add watermelons.txt
    
    git status
    git log
    
  4. Create a commit.

    git commit -m "add cherries, strawberries, and watermelons"
    
    git status
    git log
    
  5. Create a blank github repo called "fruit-basket".

  6. Set your remotes (follow the instructions in the new github repository, it should look something like below).

    git remote add origin git@github.com:XXXXX/XXXXX.git
    git push --set-upstream origin master
    
  7. Push the commit.

    git push
    
    git status
    git log
    

❇️ Example: universe

  1. cd into your directory ~/Development/universe

  2. run pwd and ls to remind yourself where you are and what is there

  3. double check to make sure there are no untracked changes, or tracked changes in the "staging area" that haven't been committed yet. Take a look at the commit log. Build a mental model of what your repository looks like. Then, run a git pull just in case, to grab any new changes from GitHub that you're missing.

    git status
    git log
    git pull
    
  4. open mars.txt in sublime text and add a new fact to it about mars and save the file

  5. add that change to the staging area. But first, glance at your staging area (git status) and your commit log (git log) to update your mental model

    git status
    git log
    git add solar_system/planets/mars.txt
    
  6. Glance at your staging area (git status) and your commit log (git log) again to update your mental model. Now commit those changes.

    git status
    git log
    git commit -m "add mars"
    
  7. push your commit

    git push
    

    and check your repository online by refereshing the page in github

➡️ Try It

Repeat the steps above 3 times, each time for a different planet

bonus

Try making a commit that involves changing multiple files (do two planets in the same commit)