software-development-lessons

Version Control with Git

This lesson goes over version control using git.

Slides

Topics

Version Control

How to track what changed, who changed it, and why.

TODO

โœ… Setup git to track changes in your notes/ directory

(you will need install xcode command line tools xcode-select --install)

โœ… Make a commit

โœ… Try using the source control tab with GitLens extension in VSCode and GitPod workspaces

bg contain

Git is used by >90% of Fortune 100*

Scenario

bg contain

bg contain

Terms

Repository tracks and saves history of changes in a git project

Commit a snapshot in the repository timeline

Branch an independent version of the repository

Merge a git command that combines 2 branches into 1 branch

Git CLI (Command Line Interface)

git init create an empty Git repository or reinitialize an existing one

git status see status of this repository

git log show commit logs

git add add file contents to the index

git commit record changes to the repository

git branch list, create, or delete branches

git merge join two or more development histories together

git reset reset current HEAD to the specified state

(๐Ÿ˜… thatโ€™s a lot to remember. we can just use VSCode for now ๐Ÿ˜Ž)

Initialize a local git repository (CLI)

In order to track changes in your notes/ directory

  1. Open a terminal and navigate to your notes/ directory

  2. Type in git init to setup a new git repository

    This command creates a .git/ folder to track changes

Make a commit (CLI)

  1. Use git add to stage files you want to commit

    git add . If you want to add everything

  2. git commit -m "Initial commit"

Initialize a local git repository (VSCode)

This creates a .git/ folder to track changes

Make a commit (VSCode)

  1. Open source control panel
  2. Stage changes
  3. Enter commit message
  4. Click โ€˜โœ“ Commitโ€™

bg right

Commit Message

Commit messages help a future reader quickly understand what changed and why it changed

Please read this post on Best Practices

Commit Message Examples

Bad

debugging I added a delete route to the accounts controller chanages

Good

Enable logging globally Add account delete route

Git GUI Tools

I highly recommend using a git GUI tool

VSCode source control with GitLens

Sourcetree

GitHub Desktop

bg right

Resources

First Draft: Using Git

First Draft: Command Line Git

GitLens VSCode extension

Git Cheatsheet

First Draft: Git Aliases