Lecture 40

git and GitHub

MCS 275 Spring 2023
Emily Dumas

Lecture 40: git and GitHub

Reminders and announcements:

  • Please complete your course evaluations.
  • Project 4 autograder is open
  • Upload Project 4 as a ZIP file if you need subdirectories

Last time

We discussed enough of the version control system git to allow a solo project to maintain a documented, linear, history of changes.

Workflow

  • Initial setup: git init
  • Work session:
    • Make and test changes
    • git status   (optional)
    • git add file1
    • git add file2
    • git status   (optional)
    • git commit
  • View history: git log
  • View other file versions: git show COMMIT:FILE

What's a good commit?

A set of changes with a single purpose.

Usually that means a small number of changes.

(If several things changed, git add --patch will let you stage just part of the changes.)

Today

  • How to host a copy of a repo remotely (e.g. on GitHub) and interact with it
  • Complications arising when collaborating
  • Improving the workflow

GitHub

Launched in 2008 ($\approx$3 years after git released).

By 2013, hosted 5 million repositories.

Google's competitor (Google Code) shut down in 2015.

GitHub acquired by Microsoft in 2018.

Over 370 million repositories as of January 2023.

GitHub hosts official repositories (or mirrors) for

Reminder

Monoculture can be dangerous.

GitHub is becoming a single point of failure in software development.

But of course I want to teach the tools people use!

GitHub steps

Suppose you want to host a local* git repo on GitHub.

  • One time only: Make an account at github.com
  • Once per machine: Create an SSH key and add it to your GitHub account
  • Once per project:
    • Create repo on github.com (named, unlike git repos). Can be public or private.
    • push from local repository to GitHub

* I recommend you always make a repo locally before putting it on GitHub.

git push

Contact a remote repository and send it commits that are in our database but not theirs.

Fails if remote has changed since our last push!

Viewing on GitHub

GitHub main interface shows file/dir list and renders any README.md (or README.txt).

Has syntax highlighting, can render .ipynb files, ...

Can browse commits, view repo at previous state, ...

Editing on GitHub

It is possible to add/edit files directly on GitHub.

These actions create new commits.

Using this feature is rare in most projects.

git pull

Contact a remote repository and get commits from its database that are not yet in ours.

May trigger a merge if there have been changes to both local and remote since we last pulled.

Next time

Branching workflow.

References

Revision history

  • 2023-04-25 Initial publication.