Media Computation Skills Lab

MTEC 1003

Lab 3 — Creating Local and Remote Repositories

In this lab, you’ll be:

  1. creating two repositories, one local and one remote
  2. linking the two with each other so that they can be synchronized
  3. associating a name and email address with your local repository
  4. creating a README.md file to describe your lab
  5. sending those changes to your remote repository on github

your git cheatsheet: A 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. You can set this up anywhere on your computer, but to keep things organized, we recommend that you create the repository here:

/Users/[yourUserName]/Desktop/myClasses/mtec1003/lab-03-git-intro

cd ~/Desktop/myClasses
mkdir mtec1003
cd ~/Desktop/myClasses/mtec1003
mkdir lab-03-git-intro
cd lab-03-git-intro
ls -al
total 0
drwxr-xr-x  2 bree  staff   68 Feb 26 07:52 .
drwxr-xr-x  3 bree  staff  102 Feb 26 07:52 ..
git init
Initialized empty Git repository in /Users/[yourUserName]/Desktop/myClasses/mtec1003/lab-03-git-intro.git
ls -al
ls .git
# in the directory of your repository
git config user.name  "my first and last name"
git config user.email "my@email.address"
git config -l

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.

git remote -v
git remote add origin https://github.com/yourGitHubUserName/lab-03-git-intro.git
git remote -v
origin	https://github.com/[yourGitHubUserName]/lab-03-git-intro.git (fetch)
origin	https://github.com/[yourGitHubUserName]/lab-03-git-intro.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.

git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
git status
# 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)
git add --all
git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   README.markdown
#
git commit -m "added a README file"
[master (root-commit) 5b24d27] added readme
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.markdown
git status
# On branch master
nothing to commit, working directory clean
git log --color
commit 5b24d2777a602908978916ca8fe9c8dd2ed6036b
Author: bree <[you]@citytech.cuny.edu>
Date:   Wed Mar 5 11:45:21 2014 -0500

    added readme
git push origin master
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/[yourGitHubUserName]/lab-03-git-intro.git
 * [new branch]      master -> master
This is lab 03...
It's about creating local and remote repositories, and saving new data to these repositories.
git diff --color

MTEC 1003 - Media Computation Skills Lab