Introduction to git and GitHub

Irena Papst

This talk is available online here:

https://papsti.github.io/talks/2023-08-23_intro-to-github.html

Filename nightmares



Previous version grief

Collaboration pain



Setting the scene

The lingo

  • git: version control program

  • GitHub: an online service that enables you to share, backup, and collaborate on git repositories

  • Repository (“repo”): project folder

High-level overview

Getting set up

  1. Register for a free GitHub account here

Getting set up

  1. Install git followed by GitHub Desktop (both available in Service Gateway)
  2. Configure git for GitHub Desktop

Working alone

Create a central remote repository on GitHub.com

Create a central remote repository on GitHub.com

Create a central remote repository on GitHub.com

“Clone” a copy of the repo locally

“Clone” a copy of the repo locally

Add some content

Ignore unnecessary files

Option 1: point and click in GitHub Desktop

Option 2: point and click in GitHub Desktop

Ignore unnecessary files

Option 3: add patterns to the .gitignore file

Ignore unnecessary files

Option 3: add patterns to the .gitignore file

Ta-da!

Inspect changes using “diffs”

Commit your changes

Push your changes

Push your changes

You can see the results of that push here.

Working with others

Inviting collaborators

Pull from origin

Pull from origin

Branching

Branching

Branching

Pull request

Pull request

Pull request

Merge conflicts

  • git is great at automatically consolidating sets of changes between versions
  • When it needs help, it creates a merge conflict to flag conflicting changes
    • e.g. when two people make different change to the same part of the same file
  • Fear not!

Merge conflicts

Merge conflicts

The rewards

Managing version history

Managing version history

Return to a previous version

Collaborate simultaneously

Project management with Github

Issue

Issue (Action) Item

  • For example: fixing a bug, implementing a new feature, documenting your work, writing a report, etc.

“Code” reviews

  • Track changes-like editing/commenting for code and/or text
  • Let’s look at an example

Summary of workflow

  1. Create a remote repository to house your project on GitHub.com.
  2. You and all collaborators should clone a copy of the repository locally to their own machine.
  3. Create a first, minimal version of your project code. Commit it to the main branch of your repository.
  4. Decide on a “feature” (analysis, plot, manuscript text chunk, etc.) that you want to create or edit. Create a GitHub issue associated with this action item.
  5. Create a new branch from the version of the code where you want to complete this task. The sole purpose of this branch is to address the issue.
  1. Commit changes addressing this issue and push to remote every so often.
  2. Once you’re satisfied that you’ve addressed the issue, push one final time, pull the latest version of main into your working branch, and then open a pull request. Use keywords in your pull request to close issues that have been addressed.
  3. Optionally solicit a code review from a collaborator.
  4. Once any code review and changes are complete, merge the pull request into the original branch from which you branched.
  5. Delete the new feature branch.
  1. Rinse and repeat steps 4-8 until your project is done!

Other resources

Thanks!

Github

@papsti

@phac-nml-phrsd

Email

irena.papst@phac-aspc.gc.ca