What is Git?

  • Git is a version control tool that tracks changes to your code over time, so you can see what changed, when, and roll back if needed.1
  • GitHub is a website that hosts git repositories online, so code can be shared, downloaded, and collaborated on.2
  • In this course, we’ll mainly use git to clone (download a copy of) exercise templates from GitHub.

Why Use Git and GitHub?

  • Get starter files instantly: cloning a repository downloads a ready-to-go project folder in one command.
  • Track your own changes: git keeps a history of every change you save, so you can always see or undo past work.
  • Industry-standard skill: git and GitHub are used by nearly every professional software team.

How Can I Install Git? (Mac)

  • Git is often already installed on Mac as part of the Xcode Command Line Tools. Open Terminal and run:
1git --version
  • If it’s not installed, macOS will prompt you to install the Xcode Command Line Tools — accept the prompt.
  • Alternatively, if you use Homebrew:
1brew install git

How Can I Install Git? (Windows)

  • Download and run the installer, Git for Windows, from the link below. Accept the default options during installation.
  • Reference: Git Downloads (Windows)

How Can I Test That Git Is Installed?

  • Close and reopen your terminal, then run:
1git --version
  • If installed correctly, you’ll see output similar to:
1git version 2.55.0

How Do I Set Up My Identity?

  • Before you can save (commit) changes, tell git who you are. This is a one-time setup:
1git config --global user.name "Your Name"
2git config --global user.email "username@catamount.wcu.edu"

How Do I Clone a Repository?

  • git clone downloads a full copy of a GitHub repository into a new folder on your computer:
1git clone <repository-url>
  • This creates a new folder (named after the repository) containing all of its files, ready for you to work with.

How Do I Save My Changes Locally? (add, commit)

  • Once you’ve made changes to files in a repository, use this basic workflow to save a snapshot of your work:
1git add .
  • git add stages your changed files, marking them to be included in the next save.
1git commit -m "Describe what you changed"
  • git commit saves a snapshot of your staged changes, along with a short message describing what changed, to your local repository history.

  • Note: git add and git commit only save changes on your own computer — nothing leaves your machine. You do not need to run git push, and you should not push your changes back to the exercise template repository you cloned from. Using git add and git commit as you work still gives you a full local history you can look back through (with git log) or restore from if needed, without ever touching the original GitHub repo.


How Do I Look Back Through My History and Restore Changes?

  • git log shows the history of every commit you’ve made, most recent first:
1git log
  • For a shorter, one-line-per-commit view, add —oneline:
1git log --oneline
  • Each commit has a unique ID (a long string of letters/numbers, shown in full with git log, or shortened with git log --oneline). You’ll use this ID to go back to that point in time.

  • If you’ve made changes but haven’t committed them yet and want to undo them, restore a file back to its last committed version:

1git restore <filename>
  • If you want to bring back a file exactly as it was in a past commit, use its commit ID:
1git checkout <commit-id> -- <filename>
  • This copies that file from the specified commit into your working folder, without affecting the rest of your history — a safe way to recover a previous version of your work.

Footnotes

  1. Git ↩

  2. GitHub Get Started Guide ↩