Welcome, Guest User :: Click here to login

Logo 67272q

Lab 1: Setup; Using Git

Due Date: January 14

Objectives

  • Get student laptops ready to build applications
  • Install and configure Git on your laptop
  • Learn basic Git functions through exercises
  • Get students acclimated to using the PaizaCloud IDE

README.md

Part 1: Setup

PaizaCloud

This semester in 272, we will be using a new, online, platform called PaizaCloud to build and run our web applications. This allows people on Windows, Mac, or Linux to run code in the same environment which will dramatically reduce time and frustrations on installing different pieces of software. Also, because of a standardized environment, the TA and CAs can be more helpful in issues that may arise in building code.

If you really want to use your local machine, you can use Visual Studio Code [https://code.visualstudio.com/].

Step 0: Registration

Signup yourself with your andrew email to https://paiza.cloud/en/
PaizaCloud Home Dashboard

PaizaCloud will send you a verification email, please verify your email using the link that they sent you. Now, you will be able to login with your email id and password.
PaizaCloud Login

Important: Enter the Coupon Code

Now go to yourusername menu displayed on the top right hand and select "Account" option from the list of items. Choose "Basic" plan. Check the coupon code and enter the coupon code that is given to you. Fill in your details such as First Name,Last Name and other details [Do NOT enter the credit card details].After successful subscription, you can proceed to the next steps.

Step 1: Create a server on PaizaCloud

You will get the following screen once you have logged in successfully. Now you need to create a server.Click "New Server" to create a server.
PaizaCloud Server

Type myserver-1 as the server name.
Choose Web application development: Node.js,Ruby on Rails
Make sure “Always-on “ Basic plan only is checked.
Press the “New server” button to proceed and create new server.
PaizaCloud Server

Step 2: Understanding the menu on PaizaCloud

The server is created now.Press the little icon on the top left hand side to get the menu items. Read the menu so that you can choose the items appropriately.
PaizaCloud Menu

Step 3: Create a rails application

There are two ways of generating a rails application. One way is to point to Rails -> rails new from the menu.
PaizaCloud application

And, type in the name of the app that you want to create. I have used helloworldapp as my first application name. Press Run so that rails generate the framework for your app.
PaizaCloud application

Another method to create an app is to click on New terminal from the menu and type

rails new helloworldapp 

and hit enter. You can choose either of these methods to create a railsapp.
We strongly recommend to always use the terminal to create the rails application.
PaizaCloud application

You will see that rails generates so many files for your application. Once it is completed, you will get a similar screen as below.
PaizaCloud application

On the left side navigation bar, you will see that under /home/ubuntu folder your newly created helloworldapp is created. Go through it to see what all files are generated by rails.
PaizaCloud application

Now, in order for you to work with your app, go back to your terminal and type

cd helloworldapp/ 

and press enter
Now you will be inside the helloworldapp folder.
PaizaCloud application

Step 4: Start the server and view the rails application in a browser

Finally, we will see if rails is working fine and that we can access the application through our browser. You can achieve this step by typing the below command and press enter. You will see that the server has started.

rails server 

PaizaCloud server

To view the application in the browser, Open the menu and select the second option Browser(127.X.X.X:3000) or, on the left hand side , you will see a browser icon and you will get the Welcome screen from rails!
PaizaCloud browser
or
PaizaCloud browser

PaizaCloud browser

Step 5: Download the rails application as a zipped file

To download the project, right click on the helloworldapp folder and click Download to download the application to the machine.
PaizaCloud download


Part 2: Using Git

Installing Git

  1. If you used PaizaCloud, Git is already installed for you! If you installed locally on your Mac, please be sure Git is installed properly before continuing.

  2. There are a number of graphical user interfaces available for Git if you installed locally on a Mac, but using the command line to manage Git is easy and will be what we use for all lab instructions. For the remainder of the lab today, we recommend you use the command line.

Configuring Git

  1. There are a number of online resources for Git. There is a nice cheat sheet here. Open one of these now in a browser for reference purposes. Also, note some nice Git resources at www.gitready.com that might also be helpful later in the course.

  2. Create an account on [Github] (https://github.com/). You will have to replace "Your name" with your username and your "your@email.address" with the email you used here, in the next step.

  3. Setup your git installation with your author's information. That way, when you make a commit, you are "signing" it so other developers know who made the commit.

     git config --global user.name "Your Name"
     git config --global user.email "your@email.address"
    

    Note: The quotations are important.
    In order to check the username and the email you entered please enter the following:

     git config --list
    
  4. (optional) If you installed locally, you can also configure your .gitconfig file to make output certain colors and handle other basic chores. My .gitconfig file can be seen in my dotfiles repo on github if you are looking for an example.

Getting Started with Git

  1. To get a feel for how Git works without getting bogged down by code, we are going to set up some simple text files with material from various Monty Python movies and skits.

Start by creating a folder or directory somewhere called 'monty_python'.

   mkdir monty_python

and then switch into that directory.

   cd monty_python

Now in that directory, we will create a new git repository by typing:

    git init

Here's a screenshot to help:

Note: If you are using PaizaCloud for this portion of the lab, either create a new workspace using the "Basic" template, or within your existing workspace navigate out of the workspace directory, using the terminal command cd ~ before making the new 'monty_python' directory.

  1. To save files to a Git repo (shorthand for repository), we need to understand that Git works in a two-step process. First we send files from our working directory to a staging level. Once we have a collection of related files in staging we want to save to the repo, we 'commit' those files along with a useful message explaining what was committed. Later if we ever want a file or set of files back from the repository, we can do so using the 'checkout' process. The diagram below summarizes this:

  1. Within your working directory, create an empty file called holy_grail.txt:

     touch holy_grail.txt
    
  2. Now check that the file is untracked and needs sent to staging:

     git status
    
  3. Add the file to the staging area:

     git add holy_grail.txt
    

Tip - You can hit (the tab key) to autocomplete filenames and directories.

  1. Type git status again and verify that the file is ready to commit.

Here's a screenshot that may be helpful:

  1. Following the same previous steps, add another file called life_of_brian.txt to the working directory.

  2. Commit the files in staging to the repository:

     git commit –m "Holy Grail, Life of Brian files added to project"
    

Tip - good messages are useful; always include a description message using the –m flag!

  1. Confirm the change by running git status. Double check the change by running git log to see the list of commits:

  1. To make sure you have this git stuff down, do the following:
    a. Add one quote from each movie to its respective file:

b. Add a new file called completely_different.txt to the repository. Refer back to the previous instructions if necessary.


Stop

Show a TA that you have completed the first part. Make sure the TA initials your sheet.


Diffing and Removing Files

Now that we have a basic Git repository set up and know how to add files, we need to also learn how to remove files and how to compare versions of the same file in different levels. Let's start with removal. In the git status help, we saw the note that if we want to remove a file from the staging level.

  1. Remove the holy_grail.txt by typing the following:

     git rm holy_grail.txt
    

and verify that it's gone from your working directory.

  1. Oh snap! We didn't want to delete the file! I meant to use git rm --cached. Don't worry, it hasn't been removed from the repository yet - we've just marked the file for deletion.

  2. Get the file back by using checkout:

     git checkout HEAD holy_grail.txt
    

Note - HEAD is a pointer to your most recent commit. This could also be the SHA value of any previous commit.

  1. Add another famous quote to holy_grail.txt.

  2. Use git diff to see what has changed:

     git diff
    

  1. Stage and commit these changes:

     git add holy_grail.txt
     git commit -m "Added another quote to holy_grail.txt"
    
  2. Add another quote to life_of_brian.txt and stage the file (git add life_of_brian.txt), but do not commit.

  3. Run git diff:

     git diff
    

You should not see any output. This is because the changes are staged and ready to be committed. If you want to see the difference between the staged version and the repository version, specify the --cached flag:

  git diff --cached life_of_brian.txt
  1. Reverse your changes to life_of_brian.txt:

     git rm --cached life_of_brian.txt
    
  2. We have decided that the completely_different.txt file was unnecessary. Using git, remove the file. (On your own - see a TA if you need assistance)

  3. (optional) Add another file called pointless.txt and stage and commit it. Since that was pointless, I want to move back to the previous commit; I can do this by typing git checkout master^. (This is a relative commit name: master^ is the second most recent commit in master the branch. master~3 is the great grandparent (three before) of the most recent commit in the master branch.)

Notice now that the file pointless.txt is gone from your directory. You can get it back with git checkout master if you wish. I can also use absolute commit names and go all the way back to the beginning (in my case) with git checkout 24ac377, where this string is the commit name git assigned to my first commit (found it by using git log).

Branching and Merging

We need to add the new material from the Flying Circus to our project and to do this we will branch the project (if we don't like the changes, it will be very easy to just kill the branch and go back to master and try again – great way to safely experiment within the project).

  1. List all our current branches with:

     git branch
    

The current (and only) branch is marked with a *.

  1. Create a new branch called "television":

     git branch television
    
  2. Run git branch again to verify the branch exists.

  3. Switch to the television branch:

     git checkout television
    

  1. Add a new file called flying_circus.txt with the quote:

    "No one expects the Spanish Inquisition!"

Add this file to the repository with an appropriate message.

  1. Return to the master branch:

     git checkout master
    

You'll notice that the flying_circus.txt file disappeared! Not to worry - it will be back soon enough.

  1. Create and switch to a new branch called "movies":

     git checkout -b movies
    

Tip - in command, we created the branch and switched to it in one command by specifying the -b flag to git checkout.

  1. On this new branch, add two new files:

     touch meaning_of_life.txt mp_live.txt
    

Tip - touch is a *nix command for creating files

  1. Commit these two files using what you learned earlier in the lab.

  2. Checkout the master branch again (see previous commands for help).

  3. Merge the movies branch back into the master branch:

    git merge movies
    

Note - the branch movies still exists. If it's no longer needed, delete the branch with:

    git branch -d movies
  1. Checkout the television branch.

Notice that the new movie files are gone, but the flying_circus.txt is back in the working directory.

  1. Add a new quote to flying_circus.txt (anything will do) and commit the change to the repository.

  2. Merge the television branch back into the master branch (see #10..#11 for help).

There is obviously much more to Git, but this lab should get you familiar with the basics and started using Git and your proficiency should increase as you use it more in this course. Once the TA verifies the repo is set up, you are finished.


Stop

Be sure that the TA/professor checked your work and marked that in the checkout sheet.