Lab 6 - Prep - Creating Local and Remote Repositories
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 a README.md file to describe your lab
- sending those changes to your remote repository on github
Summary of Commands:
THESE ARE NOT LAB INSTRUCTIONS.
The following is just a reference. The lab instructions are below.
# create a local repository
git init
# configure it with your name and email
git config user.name "your name"
git config user.email "your@email.address"
# create a remote repository
curl -u 'your github user name' https://api.github.com/user/repos -d '{"name":"your repository name"}'
# link the two
git remote add origin url_to_your_repository_on_github
# two ways to show all remote repositories
git remote -v
cat .git/config
# removing a remote repository by name (usually origin)
git remote remove name_of_remote
# changing / setting the url of a named remote repository (usually origin)
git remote set-url name_of_remote new_remote_url
# look at the differences between your last save and your current changes (line by line)
git diff --color
# check on the status of your changes
git status
# "stage" or mark your changes as ready to be saved
git add --all
# save!
git commit -m 'my message'
# show a log of your changes so far
git log --color (show your changes so far)
# send to a remote repository (to submit an assignment)
git push origin master
Instructions
Set up Your Local Repository
This will create a local git repository to store your work for this lab. The repository will be in ~/Desktop/yourname/lab-06-javascript-conditionals.
- open terminal
- (if doesn’t already exist) create a folder that consists of your first initial and last name on your Desktop
cd ~/Desktop
mkdir myname
- within that folder, create another folder called lab-06-javascript-conditionals and change into it
cd myname
mkdir lab-06-javascript-conditionals
cd lab-06-javascript-conditionals
- use pwd to verify that you’re in the correct folder
- you should be in ~/Desktop/myname/lab-06-javascript-conditionals
- 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 mostly be empty
total 0
drwxr-xr-x 2 bree staff 68 Feb 26 07:52 .
drwxr-xr-x 3 bree staff 102 Feb 26 07:52 ..
- in your lab-06-javascript-conditionals folder, create your repository!
git init
- it should say:
Initialized empty Git repository in /Users/bree/Desktop/bzuckerman/lab-06-javascript-conditionals/.git/
- show that this worked by listing all files in your current directory
ls -al
- check that this shows .git
- use ls .git to show the contents of your repository (it should contain a configuration file, for example)
ls .git
- configure your name and email for your commits (these do not have to be the same as your github account)
# 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)
Create Your Remote Repository
This will create a remote git repository on github. It will also link your local repository with this remote repository. In order to submit your work, you will send your files / changes from your local repository to the remote repository on github.
- log in to github; you should see the list of repositories on the right
- you should have all of the previous lab related repositories
- go back to terminal
- using the commandline, create a remote repository on github by using the command below…
- substitute your github username where it says “your github user name” (keep the single quotes and KEEP “name”: at the end of the line; don’t change that!). the name of the repository is lab-06-javascript-conditionals (you can see that specified at the end of the command)
curl -u 'your github user name' https://api.github.com/user/repos -d '{"name":"lab-06-javascript-conditionals"}'
- it should output a bunch of text!
Enter host password for user 'bzuckerman':
{
"id": 17210769,
"name": "lab-06-javascript-conditionals",
"full_name": "bzuckerman/lab-06-javascript-conditionals",
"owner": {
"login": "bzuckerman",
...
}
- refresh your page on github
- you should see the new repository added
- go back to terminal
- make sure you’re in your local repository folder for lab-06-javascript-conditionals
- use pwd to do this
- you should be in ~/Desktop/yourname/lab-06-javascript-conditionals
- if you’re not in your lab folder, change your directory to it
- run this command to show that you have not linked your local repository to any remote repository yet
git remote -v
- it should do nothing
- now, link your local repository to your remote repository on github by using git remote add
- make sure to substitute the two spots where it says “your_github_user_name” with github username
git remote add origin https://github.com/your_github_user_name/lab-06-javascript-conditionals.git
- (alternatively, if you click on your repo you can see your remote repository’s url on the lower right hand side of the page…)
- to check that you’ve linked properly, run the following command again:
git remote -v
- it should show origin … and your repository url:
origin https://github.com/bzuckerman/lab-06-javascript-conditionals.git (fetch)
origin https://github.com/bzuckerman/lab-06-javascript-conditionals.git (push)
Creating and Saving Changes Locally, Sending to Remote Repository
In this part of the lab, you will create 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-06-javascript-conditionals
- use pwd to do this
- you should be in ~/Desktop/yourname/lab-06-javascript-conditionals
- 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
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
- create a file called README.markdown using SublimeText (see below…)
- go to Applications → SublimeText (or use Command+Spacebar to activate spotlight search, then start typing Sublime)
- once SublimeText is open, go to File → New (or Command+n) to create a new file
- save your file by going to File → Save As to save your files as README.markdown in your ~/Desktop/yourname/lab-06-javascript-conditionals
- make sure you navigate to your ~/Desktop/yourname/lab-06-javascript-conditionals before saving!
- 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.markdown
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README.markdown
nothing added to commit but untracked files present (use "git add" to track)
- 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
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.markdown
#
- 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 "added a README file"
- the output of the command should be:
[master (root-commit) 5b24d27] added readme
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.markdown
- 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 2014 -0500
added readme
- 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-06-javascript-conditionals.git
* [new branch] master -> master
- go back to github and look in your repository. you should see that file appear.
- go back to SublimeText
- add two lines to your README.markdown file
This is lab 06...
It's about JavaScript conditionals.
- save your file: File → Save or Command+s
- go back to terminal
- use git diff to show your changes
git diff --color
- use git status, add and then commit to save your changes
- use git push to send them to your remote repository
- if you click through the filename on github, you’ll see your changes
- when you’re done try the following:
- show your remote url…
- add it to your README file and save it!
- commit your change…
- set your remote url to some url that does not exist (change the lab number to 7, for example)
- push the change to your remote
- note the error!
- set your url appropriately
- attempt to push your change again