Version control
A version control system is a program that tracks metadata about edits or changes made to files in a given folder, and makes it easy to track changes, revert changes, and synchronize changes between users. Version control systems are widely used in industry. The allow lets multiple people in different locations work together, editing the same files, and not have to worry about overwriting each other's changes. Version control also makes it easy to undo a messy change!
We strongly encourage you to use a version control system for your programming assignments, whether you are working by yourself, or with a partner. It is good for you to learn how to use version control, and it will help you with the development of your software.
The remainder of this document gives you information about using Git, one of the most popular version control systems. The SEAS Academic Computing Group provides an online git repository and project management website. The following section tells you how to register and use this website, and we then give you some tips on using git.
Git was originally developed by Linus Torvalds for development of the Linux kernel. Git is a distributed version control system. Centralized version control software typically supports a single, remote repository from which all users "checkout" files. All changes must be sent to the repository to be tracked and shared. A distributed version control system supports many local repositories which each track changes and can synchronize with each other in a peer-to-peer fashion.
code.seas.harvard.edu
The SEAS Academic Computing group provides an online git repository and project management website at https://code.seas.harvard.edu. We recommend you use it for your programming projects in CS61.
The remainder of this page gives brief instructions for getting started on the repository, specialized, where appropriate, for CS 61. For more detailed instructions, please refer to the SEAS Code Repository documentation.
Signing up
- Go to https://code.seas.harvard.edu/login
- Enter in your FAS credentials (i.e., the same credentials you use to ssh to cs61-login.seas.harvard.edu).
- You may be directed to an OpenID Verification page that asks you to confirm your identity. Click the "Allow Always" button on the right of the screen. You may then be asked to enter some details for your profile, but will eventually see your Dashboard.
- The next step is to add your SSH keys
- SSH keys provide you with a way to easily access your git repositories from your CS61 VM.
- If you haven't already, you need to create an SSH key on your CS61 VM.
- You can check out this handy HCS
tutorial, or
follow these steps:
ssh
to your VM.- Run "
ssh-keygen -t dsa
" and follow the instructions. - You have now created your ssh keys. They live in the directory
~/.ssh
- Now run "
cat .ssh/id_dsa.pub
" to display your public key. - Copy your public key (that is, select the text on the screen, and copy it to the clipboard), and in the SEAS Code Repository, click "Add SSH Key", and paste your key into the field, and click "Save".
Creating a project for your team
Only one team member needs to do these steps:
1. Create a project: name it CS61 (username 1) (username 2)
2. Create a repository for the project with the same name
3. Add your partner to the project
4. Make sure your repository is private:
- go to the main page of the repository
- click on "Edit Repository"
- check "Private Repo"
- click "Edit Repository" to save changes.
Initializing your local repository
To get your project under version control, each member of your team needs to create a local copy of the repository, following these instructions:
1. Log in to your CS61 VM
2. Configure your git "identity":
git config --global user.name "Your Name"
git config --global user.email "username@fas.harvard.edu"
3. Rename your old lab directory so it doesn't get overwritten
4. Make a local copy of the repository:
git clone
git://code.seas.harvard.edu/PROJECT_NAME/REPOSITORY-NAME.git
NAME_OF_DIRECTORY
(Note: if you get an error about "sha/ref", try
git clone git@code.seas.harvard.edu:PROJECT_NAME/REPOSITORY-NAME.git NAME_OF_DIRECTORY
or edit the address in the config file in the .git folder in your
repository root (i.e. edit the file ".git/config) to point to
git@code.seas.harvard.edu:PROJECT_NAME/REPOSITORY-NAME.git
)
cd NAME_OF_DIRECTORY
5. Now one member of your team will populate the repository with the lab files:
- Copy the contents of the lab directory into the new repository folder:
cp -R ../OLD_LAB_DIRECTORY/* .
(from within the new repository
directory)
- Add the files to the local repository:
git add *
(from within the local repository directory) - Push the changes to the remote repository:
git commit -a -m "Initial commit."
git push origin master
6. Finally, the other member of your team will pull down the new files:
git pull
from within their local repository's directory
If all went well, they should now have all of the files uploaded in step 5!
Using git
Academic Computing has an introductory guide to git on their website https://ac.seas.harvard.edu/display/USERDOCS/Introduction+To+GIT, but here are a few commands you'll need to be familiar with.
git add
adds a file or directory to your local repository git commit -a -m "Your message"
commits all of the changes you have made to files in your local repository. Commits can be pushed to the remote repository to share with your partner, and also provide places to go back to if you make a mistake. Don't forget to commit often!!!git push
pushes your local commits to the remote repository.git pull
pulls changes from the remote repository. If there are conflicts, you will need to resolve them by editing the file that has conflicts to remove them, and then committing the merged changes.git diff
can be used to view the changes you have made since your last commit. You can also use it to view the changes between other commits.