Lab 10 - Prep - Creating Local and Remote Repositories, Warm-Up Programs
In this lab, you’ll be:
- Creating a repository on the GitHub website
- Cloning the repository on your local machine
- Associating a name and email address with your local repository
- Editing the README file in your local repository
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-10-functions
- 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-10-functions
git clone https://github.com/your_username/lab-10-functions.git
- The output should be:
Cloning into 'lab-10-functions'...
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-10-functions).
- Use the git remote command.
cd lab-10-functions
git remote -v
- You should see:
origin https://github.com/your_username/lab-10-functions.git (fetch)
origin https://github.com/your_username/lab-10-functions.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-10-functions
- use pwd to do this
- you should be in ~/yourname/lab-10-functions
- 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 10 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 10...we're revisiting functions"
- 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-10-functions.git
* [new branch] master -> master
- go back to GitHub and look in your repository. You should see the changes in the Readme file.