Lab 9 - Prep - Creating Local and Remote Repositories, Warm-Up Programs
In this lab, you’ll be:
- creating two repositories, one local and one remote
- linking the two with each other so that they can be synchronized
- associating a name and email address with your local repository
- creating the following programs:
- tens
- *sum
- *fizzbuzz
Create Your Remote Repository
This will create a remote git repository on github.
- Go to your account home (github.com/username).
- Click on the Repositories tab.
- Click the green New button on the right side.
- Give your repository the name lab-09-counting
- The repository should be public (the default).
- Click "Initialize this repository with a README".
- Click Create Repository.
- Refresh your main GitHub page and you should see the new repository.
Cloning your repository
This will clone the repository you just created on GitHub on your local machine.
- open terminal
- (if doesn’t already exist) create a folder that consists of your first initial and last name in your home directory
cd ~
mkdir myname
- use pwd to verify that you’re in the correct folder
- you should be in ~/myname/
- if you’re not, cd into it
- to prove that this is not yet a repository, list all files in your current directory
ls -al
- it should contain only your previous labs
- it should not contain any .git folders
- Make sure again that you're in the correct directory! (/Users/student/myname or ~/myname)
- Clone the GitHub repository you just created: lab-09-counting
git clone https://github.com/your_username/lab-09-counting.git
- The output should be:
Cloning into 'lab-09-counting'...
remote: Counting ojects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
- Check to make sure you've linked to your remote repository:
- Change into your repository directory (lab-09-counting).
- Use the git remote command.
cd lab-09-counting
git remote -v
- You should see:
origin https://github.com/your_username/lab-09-counting.git (fetch)
origin https://github.com/your_username/lab-09-counting.git (push)
- configure your name and email for your commits
# in the directory of your repository
git config user.name "my first and last name"
git config user.email "my@email.address"
- finally, use git config again to see if this worked:
git config -l
- (use should see your name and email appear in the configuration)
Creating and Saving Changes Locally, Sending to Remote Repository
In this part of the lab, you will edit a text file in your local repository, and then you’ll send it to your remote repository.
- open terminal
- make sure you’re in your local repository folder for lab-09-counting
- use pwd to do this
- you should be in ~/yourname/lab-09-counting
- if you’re not in your lab folder, change your directory to it
- if this doesn’t exist yet… make sure you completed the beginning part of this lab
- use git status to show that there aren’t any changes yet
git status
- it should give the following output
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
- You will have a file called README.md in your lab 09 directory. Open it using SublimeText (see below…)
- Go to Applications → SublimeText (or use Command+Spacebar to activate spotlight search, then start typing Sublime)
- Once SublimeText is open, open the README.md file by going to File → Open
- Add the following to your file: "This is lab 11...we're continuing with JavaScript for loops and drawing on a canvas."
- Save your file by going to File → Save (or command+s).
- Switch back to terminal
- Use git status to show that you’ve made changes
git status
- it should give the following output; notice that it contains README.md
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in the working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
- if we want to save this file in the repository, we have stage it (that is, mark it as something that we’re ready to save / commit)
git add --all
- to check that you’ve staged your commit, use git status again
git status
- it should output the following text (note that README.markdown moved from untracked to Changes to be committed)
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
modified: README.md
- now we’re ready to commit (that is, save the file to the local repository); everything after the -m is the message that will be associated with the changes that you’ve made
git commit -m "edited the README file"
- the output of the command should be:
[master 5b24d27] edited the readme file
...etc
- check the status again
git status
- notice that there is nothing staged and no more changes!
# On branch master
nothing to commit, working directory clean
- to show the changes that you’ve saved so far, use git log
git log --color
- it should show you the following…
commit 5b24d2777a602908978916ca8fe9c8dd2ed6036b
Author: bree <bzuckerman@citytech.cuny.edu>
Date: Wed Mar 5 11:45:21 2015 -0500
edited the README file
- you can share your changes / send them to a remote repository by using git push
git push origin master
- it should result in:
Counting objects: 3, done.
Writing objects: 100% (3/3), 242 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bzuckerman/lab-09-counting.git
* [new branch] master -> master
- go back to GitHub and look in your repository. You should see the changes in the Readme file.
Instructions for Warm-Up Programs
Note that ALL OF THESE FILES MUST BE SAVED IN THE LOCAL REPOSITORY THAT YOU CREATED FOR THIS LAB.
tens
Write a program that counts down from 100 to 0 by 10’s, but skip 50
- using SublimeText, create a new file called tens.html in your repository directory: ~/Desktop/bzuckerman/lab-09-counting/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- output a countdown to the console that starts with 100 and ends at 0
- the program should count down by 10’s
- use a for loop to do this
- set the start by changing the beginning of your loop (var i = …)
- set the end by changing the middle of your loop (i >= …)
- count by 10’s by changing the end of your loop (i = i - …)
- skip 50
- do this using an if statement
- the if statement should be inside your for loop
- example output is below
100
90
80
70
60
40
30
20
10
0
- save your file in SublimeText
- use git status, add, commit, and push to save your file in version control and submit it
*sum
Write a program that asks for three numbers. It will print out the sum of all three numbers.
- using SublimeText, create a new file called sum.html in your repository directory: ~/Desktop/bzuckerman/lab-09-counting/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- ask for three numbers
- use a for loop to do this
- keep track of the sum
- output the sum at the end of the program
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) Number plz
> 23
(prompt) Number plz
> 2
(prompt) Number plz
> 5
The sum is 30
- save your file in SublimeText
- use git status, add, commit, and push to save your file in version control and submit it
*fizzbuzz
Count from 1 to 100, but print out fizz or buzz depending on special conditions.
- using SublimeText, create a new file called fizzbuzz.html in your repository directory: ~/Desktop/bzuckerman/lab-09-counting
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- print out 1 to 100 …with the following exceptions:
- for multiples of three, print out “Fizz” instead of the number
- for multiples of five, print out “Buzz” instead of the number
- for multiples of both three and five print “FizzBuzz”
- example output is below:
1
2
Fizz
4
Buzz
Fizz
.
.
14
FizzBuzz
16
.
.
98
Fizz
Buzz