Skip to content

Quintessential Git

Dan edited this page Sep 29, 2016 · 1 revision

My cheat sheet for Git

Initial Setup

git config --global user.name "Your Name"
git config --global user.email "your_email@whatever.com"
git config --global core.autocrlf true

Common Aliases

git config --global alias.a add
git config --global alias.l "log --graph --date=short"
git config --global alias.s status
git config --global alias.co checkout
git config --global alias.d diff
git config --global alias.b branch
git config --global alias.u rebase
git config --global alias.c commit
git config --global alias.p pull
git config --global alias.pr "pull --rebase"
git config --global alias.pu push
git config --global alias.h 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.t 'cat-file -t'
git config --global alias.d 'cat-file -p'

Clone specific remote branch

git clone -b <remote-branch> <url>

Switch to remote branch and setup tracking branch

git checkout -b <tracking-branch-name> remotes/origin/<remote-branch-name>

Undo the act of committing

git reset --soft HEAD^

Undo the act of committing and everything you'd staged

git reset HEAD^

Completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit

git reset --hard HEAD^

Untrack Files

git rm --cached filename
git rm -r --cached <your directory>

Ignore File Mode Changes

git config core.filemode false

Accidentally committed during conflict resolution and now I can't continue the rebase..

git reset --soft HEAD^

Show remotes

git remote -v

Change/Set/Update Remote

git remote set-url origin <url>