Skip to main content.

Git Lab: Gitting--er, Getting Started

Due Sunday Monday at 11:59 p.m.

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 will not use visual Git tools until you are confident in your version control skills).

Objectives

Part 0: Set Up

Install and Set Up Git

Creating Your 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 directory/folder where you want to store your code repositories for this class. (You may need to create that directory first.)
  2. In GitHub classroom, copy the https repository URL from the "Code" button.
  3. Run the command:
    git clone <your repository URL>

    If you see an error about needing an access token, create a personal access token.

Learn about Git and GitHub

  1. In your browser, go to your GitHub repository for this assignment. The README.md file is rendered and displayed below the top-level source code.
  2. Open README.md in your favorite text editor. Compare the contents of the file to what is displayed. How is a top-level heading represented?

    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. We'll come back to this later.

  3. Read the README.md file to learn about Git and GitHub.

In general, a README file gives a user information about software. We'll also use the README file to help us communicate between student and professor.

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 create an About.md file.

Creating and Merging a Branch

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

  1. Create a branch by running git branch practice. You are still in the main 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 About.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 About.md file (below the majors but above the honor pledge) to add a new section with a heading of "Hobbies" that describes your hobbies outside of coding and another section with the heading "Fun Fact" that gives a fun fact about yourself.
  6. Update the myfile.txt file to add another line that says "Please look at the README file."
  7. 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.
  8. 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".
  9. Switch back to the main branch by running git checkout main
  10. Merge the changes you made in the practice branch into the main branch by running git merge practice
  11. 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):