Skip to content

Latest commit

 

History

History
684 lines (436 loc) · 11.8 KB

slides.md

File metadata and controls

684 lines (436 loc) · 11.8 KB
theme highlighter lineNumbers title info drawings download exportFilename selectable aspectRatio presenter transition colorSchema class
eloc
prism
false
Intro to Git
## Git intro
persist
true
intro-to-git
true
16/9
dev
fade
light
text-center


follow along!


layout: statement class: 'text-center'

Why use version control?

collaboration
reproducibility
backups

layout: statement class: 'text-center'

Version control in academia

software
writing
citations

layout: section

Types of version control


Centralized

Decentralized

<style> h2 { @apply absolute top-5 text-center; } </style>

clicks: 3

git building blocks

  • commits: a snapshot of your files*
  • commit graph: commits are organized into a directed acyclic graph

history

*if git is tracking the files

<style> p { font-size: 0.5em; } h3 { @apply text-amber-500; } </style>


layout: statement class: 'text-center'

Create a repository

https://github.com/new


layout: statement class: 'text-center'

Clone the repository

git clone


clicks: 9

The basics

  • git add
  • git commit
  • git push
  • git pull
  • git status
  • git log

committing changes

interact with GitHub

view what you've done


layout: section

The three trees


File states

modified

staged

committed



The index / staging area

  • staging changes: git add <files>
  • viewing the index: git status

Committing changes

git commit

  • only changes in the staging area are added to the commit
  • commits need a commit message

Viewing changes

  • working tree staging area: git diff
  • staging area HEAD (the parent commit): git diff --staged

Exercise

  1. modify the contents of your README.md file
  2. stage those changes (git add)
  3. commit the changes (git commit)

Viewing history

git log


Exercise

  1. create a new file: test.md
  2. write stuff in test.md
  3. add test.md to the staging area
  4. commit your changes

layout: section

Commit philosophy


When to commit?

  • you complete a logical, atomic unit of work
  • you might want to undo those changes

What to commit?

do commit


  • source code
  • documentation

don't commit


  • build artifacts
  • large data files

Commit messages

philosophy


  • tell a story of your project's history
  • capture why

content


  • short summary
  • extended description

layout: statement class: 'text-center'

oops!

Reverting changes

git revert


Exercise

  1. revert your first commit

layout: section

Interacting with GitHub

local vs. remote repositories


layout: full


layout: full


Exercise

pushing to GitHub (the "remote" repository)

  1. verify that your local branch is ahead of the remote
             git status
  2. push your local changes to the GitHub repository (remote)

layout: full


layout: full


Exercise

pulling from GitHub

  1. edit a file and make a commit using your repo's GitHub webpage
  2. pull those changes into your local repo

layout: section

Tags and branches

a commit by any other name...


Tags

git tag -a v0.1


Exercise

  1. tag your most recent commit as v1.0

clicks: 1

Branches

<style> .slidev-vclick-target { transition: none; } </style>

Branching commands

  • create branch: git branch <branch-name>
  • change current branch: git switch <branch-name>

Exercise

  1. create a branch called cool-feature and switch to it
  2. add hello from cool-feature branch to your README.md

Merging branches


Merging branches

git merge <branch-to-merge>

  • need to be in the branch you want to merge into

Exercise

  1. switch to your main branch
  2. merge cool-feature into main

Typical feature branch workflow

gitGraph:
  commit
  commit
  commit
  branch feature1
  checkout feature1
  commit
  commit
  checkout main
  merge feature1
  commit tag: "v1.0.0"
  branch feature2
  commit
  commit
  checkout feature2
  commit
  commit
  commit
  checkout main
  commit "v.1.1.0"
  branch feature3
  checkout feature3
  commit
  commit
  checkout main
  merge feature3 tag: "v1.2.0"
  checkout feature2
  commit
  checkout main
  merge feature2
  commit tag: "v2.0.0"


layout: section

Bonus slides


routeAlias: zenodo

Archiving code with Zenodo

assign DOIs to your code

Resources


Playground: https://git-school.github.io/visualizing-git

<iframe src="https://git-school.github.io/visualizing-git" title="https://git-school.github.io/visualizing-git"></iframe>