Lab 4 - Part 1 - Creating and Setting Up Git 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
- associate a name and email address with your local repository
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-04-version-control.
- open terminal
- 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-04-version-control and change into it
cd myname
mkdir lab-04-version-control
cd lab-04-version-control
- use pwd to verify that you’re in the correct folder
- you should be in ~/Desktop/myname/lab-04-version-control
- 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-04 folder, create your repository!
git init
- it should say:
Initialized empty Git repository in /Users/bree/Desktop/bzuckerman/lab-04-version-control/.git/
- show that this worked by listing all files in your current directory
ls -al
- check that this shows .git
- by the way, what’s in that .git directory (use ls .git to take a peek)
- now… configure your user 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_user_name"
git config user.email "my@email.address"
- finally, use git config again to see if this worked:
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.
- log in to github; you should see the list of repositories on the right
- you should have 3 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, though. this is lab-04-version-control (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-04-version-control"}'
- it should output a bunch of text!
Enter host password for user 'bzuckerman':
{
"id": 17210769,
"name": "lab-04-version-control",
"full_name": "bzuckerman/lab-04-version-control",
"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-04-version-control
- use pwd to do this
- you should be in ~/Desktop/yourname/lab-04-version-control
- 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 show
- it should do nothing
- now, link your local repository to your remote repository on github by using git remote add (make sure to substitute your github username where it says “your user name”)
git remote add origin https://github.com/github_username/lab-04-version-control.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 show
- it should show origin … and your repository url
origin https://github.com/bzuckerman/lab-04-version-control.git (fetch)
origin https://github.com/bzuckerman/lab-04-version-control.git (push)