Skip to Content
Navigation:

A stick figure smiling

If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!

Illustration of a smiling stick figure with short curly hair.

Person: git has 17 million options but this is how I use it! 

getting started

start a new repo:

git init

clone an existing repo:

git clone $URL

know where you are

git status

prepare to commit

add untracked file:

(or unstaged changes) git add $FILE

add ALL untracked files and unstaged changes:

git add

choose which parts of a file to stage:

git add -p

delete or move file:

git rm $FILE
git mv $OLD $NEW

tell git to forget about a file without deleting it:

git rmcached $FILE

unstage everything:

git reset HEAD

make commits

make a commit:

(and open a text editor to write the message)
git commit

make a commit:

git commit -m 'message'

commit all unstaged changes:

git commit -am 'message'

move between branches

switch branches:

git switch $NAME OR git checkout $NAME

create a branch:

git switch -c $NAME OR git checkout -b $NAME

list branches:

git branch

delete a branch

git branch -d $NAME

force delete a branch:

git branch -D $NAME

list branches by most recently committed to:

git branch
--sort--committerdate

look at a branch’s history

log the branch

git log main

show how two branches relate to each other:

git log-graph a b

one line log:

git log-oneline

code archaeology

show who last changed each line of a file:

git blame $FILENAME

show every commit that modified a file:

git log $FILENAME

find every commit that added or removed some text:

git log S banana

diff commits

show diff between a commit and its parent:

git show $COMMIT_ID

show diff between a merge commit and its merged parents:

git show --remerge-diff $COMMIT_ID

diff two commits:

git diff $COMMIT_ID $COMMIT_ID

just show diff for one file:

git diff $COMMIT_ID $FILENAME

show a summary of a diff:

git diff $COMMIT_ID --stat git show $COMMIT_ID --stat

diff staged/unstaged changes

diff all staged and unstaged changes:

git diff HEAD

diff just staged changes:

git diff --staged

diff just unstaged changes:

git diff

configure git

set a config option:

git config user.name 'Julia'

see all possible config options:

man git-config

set option globally:

git config --global ...

add an alias:

git config alias.st status

important git files

local git config:

.git/config

global git config:

~/.gitconfig

list of files to ignore:

.gitignore

combine diverged branches

how the branches look before:

Diagram of two boxes in a row, connected by lines. The first one has a heart, the second one has a star. Branching off from the star, there is one branch with a box with a hashtag symbol, labelled “main”. The second branch consists of a box with a spiral and a box with a squiggle. The second branch is labelled “banana”.

combine with rebase:

git switch banana
git rebase main

Diagram of two boxes in a row, connected by lines. The first one has a heart, the second one has a star. Branching off from the star, there is one branch with a box with a hashtag symbol, labelled “main”. The box with the spiral and the box with the squiggle have been added on after the box with the hashtag. The box with the squiggle is labelled “banana”. The second branch, with the box with a spiral and the box with a squiggle, are drawn with dotted lines and labelled “lost”.

combine with merge:

git switch main
git merge banana
git commit

This diagram is like the “before” diagram, except now the two branches converge into a new box, with a diamond in it, labelled “main”.

combine with squash merge:

git switch main
git merge git commit
squash banana

This diagram is like the “before” diagram, except now, in the first of the two branches, after the hashtag symbol, there is a new box with both a spiral and a squiggle in it, labelled “main”.

bring a branch up to date with another branch

(aka “fast-forward merge”) main banana —0-0

git switch main
git merge banana

banana —0-2 main

copy one commit onto another branch

before: -K ← main +banana git cherry-pick $COMMIT_ID after: K main © -banana

add a remote

git remote add $NAME $URL

push your changes

push the main branch to the remote origin:

git push origin main

push a branch to the remote origin that you’ve never pushed before:

git push u origin $NAME

push the current branch to its remote “tracking branch”:

git push

force push:

git push --force-with-lease

push tags:

git push --tags

pull changes

fetch changes:

(but don’t change any of your local branches)
git fetch origin main

fetch changes and then merge them into your current branch:

git pull origin main OR git pull

fetch changes and then rebase your current branch:

git pull --rebase

fetch all branches:

git fetch --all

ways to refer to a commit

every time we say $COMMIT_ID, you can use any of these:
* a branch (main)
* a tag (v0.1)
* a commit ID (3e887ab)
* a remote branch (origin/main)
* current commit (HEAD)
* 3 commits ago (HEAD^^^)
* 3 commits ago (HEAD~3)

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)