Version Control using Git + GitHub

BC Stats Workshop

January 29, 2025

Territorial Acknowledgement

Housekeeping

  • Live coding event: (not being recorded)
  • Best practices for learning virtually
    • What to do with questions?
    • Microphones on mute
    • Getting disconnected
    • Cameras on at first.
  • Course materials
  • Our request: try your best

Workshop Code of Conduct

  • We aim to make this a welcoming and supportive environment for everyone, regardless of background
  • We encourage respectful discussion and questions throughout the course
  • Please be fully present and engaged during the session (that email can wait!)

Workshop Outline

  • Section 1: What is version control for code
    • Why do we want to use it?
  • Section 2: Working locally with Git
    • Setting up our first Git repository
  • Section 3: Remote code-hosting and GitHub
    • Sharing code on GitHub
  • Section 4: BCGov GitHub Organization
    • Coding in the open






Installation & Set Up Review

Section 1: What is Version Control?

Changes saved sequentially

Collaborating Branching

  • Multiple users: different people work on their own copy
  • Each can branch off the original work independently

Collaborating: Merging

  • Merge changes made by each person back into the same base document.
  • Documents kept in sync across different computers

Version Control Repository



A repository is a data structure that stores metadata for a set of files or directory structure, as well as a historical record of changes to the repository.

Version Control Repository

WES Project Folder
├── wes-analysis
  ├── doc
  ├── ref
  │ ├── references
  │ ├── images
  ├── plots
  ├── code
  ├── data
  │ ├── wes-results
  │ │ ├── wes-results-2019.csv <– DON’T WORRY, THESE WON’T BECOME PUBLIC!
  │ │ ├── wes-results-2020.csv
  │ │ ├── wes-results-2021.csv
| |── wes-results-2022.csv
  ├── .git <———————— THIS MAKES IT A GIT REPOSITORY!
  ├── .gitignore <————– FILES listed here are ignored by git not tracked, e.g., csv files

Section 2: Working locally with Git



  • Track changes in files
    • Source code
  • Manage versions of your work
  • Facilitates collaboration
  • Branching and merging
  • Distributed model

Preview: Git Jargon

  • repo
  • stage/add
  • commit
  • push
  • pull
  • clone
  • branch
  • fork

Preview: Bash Jargon

$ cd path/to/directory          # Go to specified directory - "quotes" are needed if there are spaces 
$ cd ..                         # Go up one directory level
$ mkdir new_directory           # Create specified directory
$ ls                            # List directories and files
$ ls -a                         # List directories and files, including hidden

Hands-On Practice





Let’s create our first repository!

The Staging Area

Best Practice Workflow:

  • stage and commit changes explicitly
  • git add <filename> followed by git commit -m ‘message’

Review: Git Jargon

$ git init                          # initiate a repository in the current directory
$ git status                        # indicate if there are any changes to files
$ git add <filename>                # add a new file/change to the staging area
$ git commit –m “commit message”    # commit all staged changes to the repository
$ git log                           # view commit history
$ git diff                          # show changes between commits
$ git restore                       # restore file/s to previous commit

Section 3: Remote code-hosting and GitHub



  • Hosting service for git repositories
  • Greatly facilitates collaboration
  • Git: Version Control +
  • Hub: Centralized repos & networking/collaborating

Git + GitHub: Working Collaboratively

Remote Repository

Hands-On Practice





Let’s create our first remote repository!

A Collaborative Workflow

Original Repository

|── planets

| |──.git

| |── mars.txt

| |── pluto.txt

GitHub Repository

|── planets

| |── .git

| |── mars.txt

| |── pluto.txt

Cloned Repository

|── planets

| |── .git

| |── mars.txt

| |── pluto.txt




  1. Initial repository set up
  1. Remote repository created & linked
  1. Local changes pushed to remote
  1. Remote repository cloned by collaborator
  1. Collaborator makes additions
  1. Collaborator updates remote with changes
  1. Collaborator changes pulled back to original

A Typical Workflow

The table below doubles as a handy cheatsheet; take a screenshot and save for future reference!

Order Action Git Command
1 (Once Only) Create remote (Done on GitHub)
2 (Once Only) Clone remote git clone https://github.com/path/to/remote
3 Update local git pull origin main
4 Make changes (Done in editor)
5 Stage changes git add numbers.txt
6 Commit changes git commit -m "Add 100 to numbers.txt"
7 Update remote git push origin main

Ignoring things

Original Repository

|── planets

| |──.git

| |── mars.txt

| |── pluto.txt

| |── data.csv

| |── .gitignore

Section 4: BCGov GitHub Organization

  • set up in early 2014
  • OCIO + BCDevExchange team
  • Digital Principles for the B.C. Government: “work in the open”
  • bcgov: open-source code
  • bcgov-c: confidential code

Section 4: BCGov GitHub Organization

BC Developer Guide

BCGov GitHub Organization

BCGov GitHub Policy Framework

BCGov GitHub Policy Framework

  • Joining
  • Opening & Contents of Repositories
  • Licensing
  • Privacy, Security, Copyright
  • Appropriate Use
  • How to’s

Mandatory Content