Git is a version control system. With git, you keep a master copy of your project on the github server, plus you can keep a copy on each computer that you use to work on the project. (For example, I have a master copy of these web pages on the server, plus a copy on each of the three computers that I typically work on). If you are working on a pair project, you might keep one copy on each partner's machine.
A general introduction to git can be found in Lesson 0.5. This includes a video demonstration.
Your daily workflow with git looks as follows:
- Always start a work session by opening up your github client (either Github for Windows, Github for Mac, or your command-line client), opening your repository, and hitting "refresh". (You may need to go to the dashboard to get it to refresh). This will get the latest versions of all the files from the server and put them into your local copy. In what follows, we'll assume you are using GHFW or GHFM; we'll refer to these as GHF*.
- Do your work.
- As soon as you change or add files during your work session, the text in GHF* that says "No uncommitted changes" will change to "uncommitted changes". You can commit your changes by clicking on "show" and choosing the changes (including new files) that you want to commit. When you do this, the little checkmark at the top of the window that says "in sync" will change to "sync". Click this icon to publish your changes to the server. We recommend you do this often. It is helpful if you use informative messages when you commit.
- During your work session, if you decide your changes have broken
things, and you want to go back to your previous commit, open up a
shell and say
git checkout master -- filename
This will replace filename in your directory with the version from the previous commit. Or you can use "." instead of filename to revert all the files in your current directory to the versions from the preceding commit. - At the end of your work session, you MUST commit your homework assignment AND YOUR LABORATORY NOTEBOOK, and sync your changes to the github server. This gets your new versions onto the server, where they will be available for your or your partner at your next session.
- Check whether your homework is visible by logging in to Github in a browser and seeing whether your changes are visible there. You can also do this by clicking "Tools" and "View on Github" in GHF*. Be sure to do this step when you are submitting your assignment!!
- NEVER exchange code by email or other channels. ALWAYS use the github repository. That way there is never any confusion about which version is the most up-to-date one. You can always use git to revert to earlier versions if you need to.
There's more, but that's the basic idea.
When you see documentation about Git, you will see lots of stuff about branches, merges, indexes, etc., etc. Don't worry about any of that. If you know about branches and want to use them as part of your workflow, feel free to do so; just submit your assignments in the branch master.
A useful tip: as soon as you get one piece of your task working, commit it. (You don't have to sync it until later). That way, if you screw things up on the next set of changes, you can always undo your bad work by clicking on "revert commit" (not "rollback", unless you know what you are doing). Reverting will get you back to the exact same state you were in when things were working, and you can try again.
Git (and other version control systems) become even more valuable when there are many people working on a project, perhaps from many different places. In a company setting, this is vital, and there are often restrictions on who can check files into the master copy of a project. Luckily we don't have to worry about these complications.
You may eventually have to deal with the situation in which you and your partner have committed incompatible changes to the server. This situation is discussed in Lesson 0.6
There are lots and lots of tutorial materials on git and github. Find your favorite on the internet. If you find some that are particularly good, please share them with the class by posting links on Piazza.
Last modified: Mon Jul 14 22:29:36 Pacific Daylight Time 2014