Lab 4 / Part 2 - 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/myClasses/mtec1003/lab-04-version-control.
- Open Terminal.
- If doesn’t already exist create a folder called mtec1003. It should live in a place like ~/Desktop or ~/Desktop/myClasses so you can easily find it. Change into that directory:
cd ~/Desktop/myClasses
mkdir mtec1003
- Or if this directory already exists, just change into it:
cd ~/Desktop/myClasses/mtec1003
- within that folder, create another folder called lab-04-version-control and change into it:
cd mtec1003
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/myClasses/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/yourUserName/Desktop/myClasses/mtec1003/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
- Before resuming work on this tutorial below, be sure you have completed all the steps outlined in last week's tutorial that teaches you how to link your local and remote repositories using a GitHub API access token.
- If you have completed Lab 3, you do not have to generate a new API token! Simply link the local and remote repositories for Lab 4 / Part 2.
- Resume FROM HERE after completing the external tutorial above.
- Now, 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/myClasses/mtec1003/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 yourGitHubUserName with your "actual" GitHub username!)
git remote add origin https://github.com/yourGitHubUserName/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/yourGitHubUserName/lab-04-version-control.git (fetch)
origin https://github.com/yourGitHubUserName/lab-04-version-control.git (push)