Git

The Stupid Content Tracker

Git Logo

Tyler Veness

What is Git?

  • Version Control System (VCS)
    • Records changes to files
    • Provides a backup plan
  • Used by major companies and more
Google Tux

Types of VCSs: Centralized

VCS Centralized

Types of VCSs: Distributed

VCS Distributed

How Git Stores Data

  • Snapshots instead of diffs
Git Storage 1 Git Storage 2

Installation

User Configuration

git config --global user.name "John Doe"
git config --global user.email "johndoe@example.com"

Workflow

What you need to know to get things done

Cloning a Repository

git clone git://github.com/schacon/grit.git
git clone git://github.com/schacon/grit.git mygrit
  • Three protocols
    • git://
    • ssh://
    • https://

Making a Repository

git init
git init --bare

  • Creates .git folder in current directory

Staging Area

Staging Area

Staging Area

File Status Lifecycle
git add git add
git rm --cached git commit [-m "message"]
git status git diff [--staged]

Staging Area

  • How to keep files out of staging area?
    • .gitignore file
# a comment  this is ignored
*.a       # no .a files
!lib.a    # but do track lib.a
/TODO     # only ignore the root TODO file, not subdir/TODO
build/    # ignore all files in the build/ directory
doc/*.txt # ignore doc/notes.txt, but not doc/server/arch.txt

Viewing History and Changes (Diffs)

git log [-#] [-p] [--stat]
git diff [<commit>] [--stat]
git diff <commit> <commit>

ex: git diff HEAD~2 HEAD

ex: git diff HEAD^

Exchanging Changes with Others

  • "Push" changes out
    git push [<local branch>]
    ex: git push origin main
  • "Pull" changes in (fetch + merge)
    git pull [<remote branch>]
    ex: git pull origin/main
  • "origin" is a remote

Creating a Branch

git branch testing
Create Branch Before

Creating a Branch

git branch testing
Create Branch After

Switching Branches

git switch testing
Switch Branch Before

Switching Branches

git switch testing
Switch Branch After

Branch Example

git branch iss53
git commit
Branch Example Before

Branch Example

git branch iss53
git commit
Branch Example After

Branch Example

git switch main
git switch -c hotfix
git commit
Branch Example 2 Before

Branch Example

git switch main
git switch -c hotfix
git commit
Branch Example 2 After

Branch Example

git switch main
git merge hotfix
Branch Example 3 Before

Branch Example

git switch main
git merge hotfix
Branch Example 3 After

Branch Example

git branch -d hotfix
git switch iss53
git commit
Branch Example 4 Before

Branch Example

git branch -d hotfix
git switch iss53
git commit
Branch Example 4 After

Branch Example - Merge

Branch Example Merge

Branch Example - Merge

git switch main
git merge iss53
Branch Example Merge 2 Before

Branch Example - Merge

git switch main
git merge iss53
Branch Example Merge 2 After

Merge Conflicts

  • Find <<<<, ----, and >>>>
  • Commit result

Resources