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
Initial repository set up
Remote repository created & linked
Local changes pushed to remote
Remote repository cloned by collaborator
Collaborator makes additions
Collaborator updates remote with changes
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”