In this followup post to the original posting on this subject, we deal with how to work with changes in the source code. There are various sorts of situations we need to handle:
- You want to push your work from your local repository to your gitorious repository, either to make it available to your team members, or to turn it in to me.
- You need to update your version of my repositories. This can happen in two ways:
- the jReality clone which you used to set up your workspace has been changed — typically to add a feature or fix a bug which is relevant to our class work.
- the course repository has been updated with a new assignment which you need to integrate into your workflow.
The solutions presented below — in contrast to the original post for gitorious — are based on the git command-line interface. So to use them, you need to have a shell open. Commands in this shell will be indicated by a leading ‘%’ to indicate a shell prompt.
Preliminary repair work. Before beginning we need to do a little repair work. Change directory to where your local git repository for the course is, and then change directory into the .git subdirectory. Use a text editor to edit the file config, to replace any occurrences of the string “assg1” with “master” (this reflects the fact that I have changed the course repository on gitorious to have only a single branch named “master”; having more was just going to be too complicated for everyone). If you have any questions, wait until the next tutorial meeting to carry this out.
Push your work up to your gitorious repository. The solution to 1. above is simple.
- First we give the commands, then we explain them:
- % cd my_local_git_repository
- % git add .
- % git commit -m “My version of Assignment1”
- % git push
- The ‘add’ command adds any files you’ve created to the list of changes to be committed to your local repository. The ‘commit’ command commits these changes to your local repository. The ‘push’ command propagates them to your gitorious repository.
- If you have your ssh keys properly installed, this should propagate your changes to your gitorious repository.
- Now you can notify your team member of the changes, or if the changes represent something that I should see, send me an e-mail notifying me. Be sure to paste the string for your gitorious repository into the e-mail, so I can install it into my eclipse workspace in case I don’t already have it or identify it (if I have installed it).
- If you want to update from your repository (either because you’ve updated it from another computer or a collaborator has done so), use the command
- % git pull
- or, in eclipse, “Team->pull”
Update your jreality to the latest version.
- Issue the following commands in a shell:
- % cd my_local_jreality_repository
- % git status
- % git checkout origin/develop -b develop
- If the last command complains that the branch “develop” already exists, then just omit the “-b develop”.
- From now on, to update jReality you can issue the command
- % git pull
- or, inside of eclipse, “Team->pull”
Update to the latest version of the course repository tu-mathvis-ws13.
In the course of the semester there will be new assignments that you need to “download” from the course repository. They do not immediately show up on your cloned gitorious repository. This is the most complicated procedure since it represents an independent branch of the repository which has to be merged into your working version. Here is how you can update using the git command line.
- Then issue the following commands in a shell:
- % cd my_local_tu-mathvis-ws13_repository
- % git status
- % git remote add teacher git://gitorious.org/tu-mathvis-ws13/tu-mathvis-ws13.git
- % git fetch teacher
- % git checkout teacher/master -b teacher
- % git checkout master
- % git merge teacher
- Explanation: The “status” command should show a “clean” branch — one with no changes that need to be committed. If there are un-committed changes, commit them first. The “remote” command adds a new remote reference to your git repository with the name “teacher”. This is my original repository that you cloned on gitorious. The “fetch” command brings over the current version of this “teacher” repository into your local repository. The first “checkout” command checks out the “master” branch of this “teacher” repository, and creates a new local branch named “teacher” for it. The second “checkout” command reverts the current working directory to the “master” branch of your local repository. The “merge” command merges the “teacher” branch into this local “master” branch. If you have been following the rules for development, then the changes from teacher and the changes you makes should be mutually exclusive and the merge should be trivial.
- You can then commit the changes and push the result onto your gitorious repository following the instructions at the beginning of this document.