git --help – A bit of background on git. – Let's get started.



git --help – A bit of background on git. – Let's get started.

0 0


01-git

Presentation over Git for Intermediate Web Design

On Github chncdcksn / 01-git

git --help

For Intermediate Web

If you would like to follow along...

01-git.chncdcksn.com

(Press the S key to pull up my notes.)

Let's start with a problem...

  • You're a chef.
  • You're wanting to share your recipes with people from across the world.
  • You want people to be able to send you suggestions about how to make your recipes even better.
              Thai Cashew with Tofu
              1. Fry tofu in a pan until it's golden brown.
              2. Add cashews and veggies and fry until golden brown.
              3. Add soy sauce.
              4. Serve with jasmine rice.
            
Here's your first (pretty awful) recipe. You post the recipe online and ask people to contribute suggestions. About a month later a suggestion appears in your inbox...
              Your Thai Cashew with Tofu is one of the most disgusting dishes
              I have ever tasted. Where's the brown sugar, you f***ing
              donkey?

              With all love and respect,
              Chef Gordon Ramsay   
            
He does have a bit of a point. Thai food generally works off of a contrast of flavors. You update the recipe to add brown sugar to contrast the salty soy sauce.
              Thai Cashew with Tofu
              1. Fry tofu and brown sugar in a pan until it's golden brown.
              2. Add cashews and veggies and fry until golden brown.
              3. Add soy sauce.
              4. Serve with jasmine rice.
            
You, being an unexperienced chef, make the assumption he meant to add the brown sugar when you add the tofu. You updated it, and soon you get another suggestion.
              You're supposed to add the brown sugar when you add the soy
              sauce. My gran is a better chef, and she's dead.

              With all love and respect,
              Chef Gordon Ramsey   
            
Not exactly the nicest way to put it, but he has a point, it doesn't make much sense to fry something in sugary oil.
              Thai Cashew with Tofu
              1. Fry tofu in a pan until it's golden brown.
              2. Add cashews and veggies and fry until golden brown.
              3. Add soy sauce and brown sugar.
              4. Serve with jasmine rice.
            
You accept the semi-constructive criticism and update the recipe. You try it and it tastes pretty good.

How can we prevent that mistake from happening again?

diff!

               Thai Cashew with Tofu
               1. Fry tofu in a pan until it's golden brown.
               2. Add cashews and veggies and fry until golden brown.
              -3. Add soy sauce.
              +3. Add soy sauce and brown sugar.
               4. Serve with jasmine rice.
            
With this, you can clearly see what lines are being changed. The minus sign at the front of the line means that the line is removed, and the plus sign means that a line is added (showing modified lines is not necessary since a modification can be indicated with a delete and an add in the same place).
               # Thai Cashew with Tofu
               ## Ingredients
               * A half block of tofu
               * Coconut oil
               * Mixed veggies (recommended: cauliflower, broccoli, zucchini,
                 carrots, bamboo shoots)
               * Soy sauce
               * Brown sugar
               * Water
               * Cornstarch
               * Bird's Eye Chili Powder
               ## Steps
               1. Add 3 tbsp coconut oil to a pan on high heat.
               2. Cut the block of tofu into 1" cubes and add to pan. Fry
                  until golden brown.
               3. Add cashews and veggies and fry until golden brown.
               4. Combine 3 tbsp soy sauce, 2 tbsp brown sugar, 2 tbsp water,
                  a pinch of cornstarch, and chili powder to taste. Add
                mixture to the pan.
               5. Let sauce simmer with veggies for about two minutes.
               6. Serve with jasmine rice.
            
After patching the recipe a couple times with the patches people sent us, we end up with this recipe. We receive another suggestion, a bit nicer this time...
              I tried adding just a little bit of lemon juice to the sauce
              and it turned out pretty good. It neutralized some of the
              saltiness of the soy sauce while keeping it's savory flavors.
              I've attached the patch.
            
                # Thai Cashew with Tofu
                ## Ingredients
                * A half block of tofu
                * Coconut oil
                * Mixed veggies (recommended: cauliflower, broccoli, zucchini,
                  carrots, bamboo shoots)
                * Soy sauce
                * Brown sugar
               +* Lemon Juice
                * Water
                * Cornstarch
                * Bird's Eye Chili Powder
                ## Steps
                1. Add 3 tbsp coconut oil to a pan on high heat.
                2. Cut the block of tofu into 1" cubes and add to pan. Fry
                   until golden brown.
                3. Add cashews and veggies and fry until golden brown.
               -4. Combine 3 tbsp soy sauce, 2 tbsp brown sugar, 2 tbsp water,
               -   a pinch of cornstarch, and chili powder to taste. Add
               -   mixture to the pan.
               +4. Combine 3 tbsp soy sauce, 2 tbsp brown sugar, 1 tbsp lemon
               +   juice, 2 tbsp water, a pinch of cornstarch, and chili
               +   powder to taste. Add mixture to the pan.
                5. Let sauce simmer with veggies for about two minutes.
                6. Serve with jasmine rice.
            
So you notice an issue with the patch system you are using. The patch is bigger than the recipe, but it doesn't have to be. You don't have to include all the lines that haven't been changed. So, you make a few changes to diff, and...
              @@ -8,2 +8,3 @@
               * Brown sugar
              +* Lemon juice
               * Water
              @@ -17,5 +17,5 @@
               3. Add cashews and veggies and fry until golden brown.
              -4. Combine 3 tbsp soy sauce, 2 tbsp brown sugar, 2 tbsp water,
              -   a pinch of cornstarch, and chili powder to taste. Add
              -   mixture to the pan.
              +4. Combine 3 tbsp soy sauce, 2 tbsp brown sugar, 1 tbsp lemon
              +   juice, 2 tbsp water, a pinch of cornstarch, and chili
              +   powder to taste. Add mixture to the pan.
               5. Let sauce simmer with veggies for about two minutes.
            
Here's the new patch. The original patch was 25 lines, and the new patch is 13 lines — an almost 50% reduction! And even better, with the new patch system, it doesn't matter how large your original file is, the patch will only contain the changes made to the file. We end up getting another email, but it isn't a suggestion.
              Hey! I'm loving your recipe! You seem to have updated it though,
              and I don't like the new recipe as much, but can't remember
              what you've changed. Do you still have the old recipe?
            
So we have our original recipe and all the patches people have sent us. Instead of having to keep a copy of each version of the file, we can rebuild any version of the recipe from the patches!

Let's say he's wanting version 4. We do the following steps in order.

Take our original file. (Version 1) Apply the first patch we were sent. (Version 2) Apply the second patch we were sent. (Version 3) Apply the third patch we were sent. (Version 4) We now have version 4! Not only that, we can get any version of this file we need, and we only have to store the small patches and not the whole recipe for each version.

So we learned a few things from this. We learned how to make some kick-ass Thai Cashew, and...

We learned the basics of git.

A bit of background on git.

git was created by Linus Torvalds to manage his main project at the time, the Linux Kernel.

Linux is an operating system, like Windows or macOS, however it is free and open-source. Since it's open-source, anyone can contribute to the project. git was made to simplify his job of sifting through the changes he was sent. It is designed so that many people can work on the project at the same time with a limited amount of interference.

git since then.

git is the main VCS (Version Control System) in use today, with millions of programmers collaborating on open-source projects around the globe using git, mostly through the social collaboration site GitHub.

Some projects on GitHub...

This presentation.

React is a JavaScript library for building user interfaces.
Angular is a web framework similar to Facebook's React.
Ericsson is a multinational networking and telecom company (some of you may remember Sony Ericsson phones). Erlang is the technology behind all telecom systems.
The vast majority of the servers your devices connect to are running Linux. If you have an Android phone, it's running Linux. If you have an iPhone or a Mac, it's running Linux's sister BSD.

Some terminology.

diff — the collection of changes made to a text file. commit — a collection of diffs used to represent one change to the codebase. branch — a collection of commits. repository — a collection of branches used to represent the all versions of a codebase.

Some more terminology

push — updating remote repositories by uploading commits not contained on the remote repository. pull — updating the local repository by downloading commits not contained in the local repository. merge — merging commits into a single commit, or merging the changes made to a branch into another branch.

Let's get started.

What we're going to do.

Create an account on GitHub.com. Download the GitHub client. Create a repository for your website. Commit a few files (index.html, styles.css, etc.) to the gh-pages branch. Push the gh-pages branch to GitHub. View your website at username.github.io/my-site. Point the domain you bought last semester to your site on GitHub. View your website at your domain (may take a few days).