Git

Learn Git version control basics in 5 minutes

TL;DR

What: Track code changes and collaborate with others.

Why: Never lose work, undo mistakes, work with a team.

Quick Start

Install:

macOS:

brew install git

Windows: Download Git for Windows

Linux:

sudo apt install git  # Debian/Ubuntu

Configure:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

First repo:

git init
git add .
git commit -m "Initial commit"

Cheatsheet

CommandDescription
git initCreate a new repo
git clone URLClone a repo
git statusCheck current state
git add FILEStage changes
git add .Stage all changes
git commit -m "msg"Commit changes
git pushPush to remote
git pullPull from remote
git logView history
git diffView changes

Gotchas

Forgot to add files before commit

git add forgotten-file
git commit --amend

Wrong commit message

git commit --amend -m "New message"

Undo last commit (keep changes)

git reset --soft HEAD~1

Merge conflicts

Edit the conflicting files, then:

git add .
git commit

Next Steps