Oh Shit Git!

Agenda

  • Introduction
  • Git basics
  • Examples
  • How to use git
  • Exercises

Purpose

To build a mental model on how git works under the hood.

Introduction

What is version control?

The non developer way

  • Project.docx
  • ProjectV2.docx
  • ProjectV2Final.docx
  • ProjectV2Final2.docx

The developer way

More specifically

In computer software engineering, revision control is any kind of practice that tracks and provides control over changes to source code.

What is git?

Why use git?

Why learn git (for real)?

Why is git hard?

How much git do I need to know?

Git basics

Nomenclature

  • Public/Private branch
  • SHA (Hash)

What is a commit?

A snapshot of the repository at a specific time

What is a branch?

A branch is just a pointer to a commit

Basic commands

Initialize a git repository


						$> git init
						

Add


						$> git add file.txt
						
  • Let git track a file
  • Include changes in next commit

Let git un-track a file


						$> git rm file.txt
						

Checkout


						$> git checkout master
						

Operates on the HEAD pointer

  • Change current branch
  • Change to a specific commit (detached-HEAD)
  • Discard changes in working directory *

Reset


							$> git reset origin/master
						

Operates on the branch pointer

  • Typically used for "removing" commits
  • Can undo "staged" changes
  • Do not use on a public branch

Revert


						$> git revert 9ba31
						
  • Undo a commit by a new commit
  • Use on public branches

Merge


						$> git merge branchA
						
  • Combines the work of two branches
  • Creates a merge commit (or does fast-forward)
  • Merge commits have two parents
  • Contains possible fixes to merge conflicts

Rebase


						$> git rebase branchA
						
  • Moves the current branch ontop of branchA
  • Creates new commits
  • Creates a linear history
  • Do not use on a public branch!

How to use git?

Commit messages

  • Max 80 chars
  • Do put some effort in writing good messages
  • Include ticket number
  • Do write a description when applicable

Commit history

  • Think of the audience, a reviewer or long term manageability
  • Consider `git merge --squash`

Workflows

How to work with git.

Basic workflow

My workflow

Takeaways

  • Keep good git commit hygiene
  • Try to keep the history understandable
  • Try to always keep the master buildable
  • Get comfortable in using git-cli

Further reading