Command Library

Search for what you want to do, or browse the official Git commands organized by workflow.

Setup

Setup

git init

Turns your plain folder into a Git repository so you can start saving code history.

Initializes a new Git repository.

git init
Setup

git clone

Downloads a full project from GitHub to your computer so you can work on it.

Downloads a project and its entire version history.

git clone <url>

Status & History

Status & History

git status

Tells you which files you've changed, which are ready to be saved, and which are untracked.

Lists all new or modified files to be committed.

git status
Status & History

git log

A time machine that shows you every save (commit) made in this project's history.

Shows the commit history for the currently active branch.

git log

Saving changes

Saving changes

git add

Tells Git: 'I want to include this specific file in my next save.'

Stages a specific file for the next commit.

git add <file>
Saving changes

git add .

Tells Git: 'I want to save ALL the changes I just made.'

Stages all changed files for the next commit.

git add .
Saving changes

git commit

Takes a picture of your staged files and saves them permanently with a message describing what you did.

Records a snapshot of the staging area.

git commit -m "message"

GitHub connection

GitHub connection

git remote add origin

Tells your computer where your GitHub repository lives on the internet.

Connects your local repository to a remote server.

git remote add origin <url>

Push/Pull

Push/Pull

git push

Sends your saved commits from your computer up to GitHub for everyone (or just you) to see.

Uploads local branch commits to the remote repository.

git push origin main
Push/Pull

git pull

Downloads any new changes from GitHub and immediately mixes them into your local files.

Fetches and merges changes on the remote server to your working directory.

git pull

Branching

Branching

git branch

Shows you all the different timelines (branches) in your project and highlights the one you're currently in.

Lists all local branches in the current repository.

git branch
Branching

git checkout -b

Creates a brand new alternative timeline for your code and immediately moves you into it.

Creates a new branch and switches to it.

git checkout -b <branch_name>
Branching

git switch

Moves you out of your current branch and into a different one you specify.

Switches to an existing branch.

git switch <branch_name>
Branching

git merge

Takes all the work from another branch and combines it into the branch you are actively in.

Joins two or more development histories together.

git merge <branch_name>

Stash

Stash

git stash

Like putting your messy desk into a drawer temporarily so you can work on something else right now.

Temporarily shelves (or stashes) changes you've made to your working copy.

git stash

Undo

Undo

git restore

Throws away any changes you made to a file since your last save.

Restores working tree files.

git restore <file>