Skip to main content.

Lab 0: Gitting--er, Getting Started

Due before Wednesday's class

Background

Knowing how to use a source control system will be an invaluable tool for you, especially in a team setting. At its heart, version control is a way to manage the changes that occur to your files over time, but that simple idea changes everything! It allows you to revisit previous versions of your code, work with different versions at the same time, and work in teams and track who made which changes. At its best, version control is like a journal that you use to track major, and minor, events in your project. At its most practical, it is like a backup system that prevents you from losing significant work if something happens to your machine. At its worst, it is simply a submit system where you only track your work when told to.

Version control systems have been around for over forty years, and Git is currently the cool tool to use. You may have heard of GitHub, the largest public repository of source code, but there are lots of places where you can host repositories. We will be using GitHub Classroom to coordinate assignments and projects.

Using source control well is not difficult, but it does take some practice and a little bit of command-line savvy (we not use visual Git tools until you are confident in your version control skills).

Objectives

Due: Before the next class (Wednesday).

Part 0: Set Up

Install and Set Up Git

Get a GitHub Account

If you don't already, you should get a GitHub account.

GitHub Classroom

Part 1: Practicing Git

Git Resources:

Reference these resources to help you use Git

Clone Your Remote (GitHub) Repository

  1. In a terminal window, navigate to the place where you want to put your code repositories for this class. (You may need to create that location first.)
  2. In GitHub classroom, copy the https repository URL from the "Code" button.
  3. Run the command:
    git clone <your repository URL>

Create and Add Files in Your Local Repository

Commit Your Updates

Now it's time to commit that new file.

Push Your Updates to the Remote (GitHub) Repository

Update Files in Your Local Repository

Now, let's update the README.md file. In general, a README file gives a user information about software. We'll also use the README file to help us communicate student to teacher. The .md extension means that it is a Markdown file. Markdown is a commonly used markup language to go from text to HTML. It's used to make pretty documents for the Web easily. Markdown is rendered by GitHub's web interface. Markdown has a relatively easy syntax to use.

Creating and Merging a Branch

Branching helps you by creating a separate sandbox to play/write code and then merge back into your main (master) branch when you're ready.

  1. Create a branch by running git branch practice. You are still in the master branch at this point.
  2. Switch to the practice branch by running git checkout practice
  3. Run git status to confirm that you're on the practice branch.
  4. Update the README.md file to add another paragraph under your name where you list your majors, e.g., "Majors: Computer Science and Mathematics". (Note: A paragraph, not a new section.)
  5. Update the myfile.txt file to add another line that says "Please look at the README file."
  6. Add both files to the staging area (you can do this using either one or two git commands) and commit them both at the same time, with a descriptive message.
  7. Push this branch to remote by running git push origin practice. This command is longer than before because the practice branch did not exist remotely yet. In GitHub's web interface, you should now see this branch listed under "branches".
  8. Switch back to the master branch by running git checkout master
  9. Merge the changes you made in the practice branch into the master branch by running git merge practice
  10. Push to the remote repository.

Log of Commit Messages

  1. Finally, run git log to see the history of commit messages.

Just the Beginning

We have just scratched the surface of what you can do with Git, but it's a good start. Later, we will use Git to help us collaborate with other students and improve our workflow.

Use Git smartly, by regularly and intelligently committing your code. Commit when you have completed (written, tested, documented) some feature or when you've fixed a bug.

Practice more using Learn Git Branching may help -- you probably just need Main: Introduction Sequence and Remote: Push & Pull -- Git Remotes

Submitting your assignment

If you followed the above directions, you will have "submitted" your assignment by putting the required files in the repository. I can only grade what has been pushed to the GitHub repository. You can look at your repository through GitHub's web interface to confirm that all the required files are there.

Grading

You will be evaluated based on the contents of your repository on GitHub (30 pts):