\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Mateusz Kocur} \pdfinfo{ /Title (git.pdf) /Creator (Cheatography) /Author (Mateusz Kocur) /Subject (GIT Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{3CA3A3} \definecolor{LightBackground}{HTML}{F2F9F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{GIT Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Mateusz Kocur} via \textcolor{DarkBackground}{\uline{cheatography.com/27298/cs/7803/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Mateusz Kocur \\ \uline{cheatography.com/mateusz-kocur} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 12th April, 2016.\\ Updated 10th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{COMMIT IDENTIFICATION}} \tn % Row 0 \SetRowColor{LightBackground} \textless{}branch\_name\textgreater{} & Last commit on the branch \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} HEAD & Current commit (parent for next commit) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} HEAD\textasciicircum{} & parent of HEAD \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} HEAD\textasciitilde{}n & n-th level parent of HEAD \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} HEAD@\{n\} & HEAD n moves ago (reflog) \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} SHA1 ID (4-20 characters) & Unique commit identifier \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{HEAD\textasciitilde{}0 == HEAD \newline HEAD\textasciitilde{}1 == HEAD\textasciicircum{}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{WORK CYCLE}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create branch for new feature} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}git checkout develop\{\{nl\}\}git checkout -b fb/new\_feature\_branch} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Add change} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\# make changes\{\{nl\}\}make compile\{\{nl\}\}git status\{\{nl\}\}git add file.c\{\{nl\}\}git diff -{}-cached (or -{}-staged)\{\{nl\}\}git commit} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Rebase} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}git pull -{}-rebase origin develop} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Push unfinished feature branch at the EoD} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}git push origin fb/new\_feature\_branch -f} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Merge with develop when finished} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\# ensure we're rebased on latest develop\{\{nl\}\}git checkout develop\{\{nl\}\}git pull\{\{nl\}\}git merge fb/new\_feature\_branch -{}-no-ff} \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Push develop} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}git push origin develop} \tn % Row Count 17 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Remove feature branch} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}git branch -d fb/new\_feature\_branch\{\{nl\}\}git push origin :fb/new\_feature\_branch} \tn % Row Count 20 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{ADD CHANGES}} \tn % Row 0 \SetRowColor{LightBackground} commit {[}-m "commit msg"{]} & Commit staged changes \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} commit -a & Add \& commit all tracked files \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} commit -{}-amend & Add changes to last commit \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} add {[}file{]} & Stage file \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} add -p & Add chunks interactively \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} diff -{}-staged & Inspect staged changes \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{UNDO CHANGES}} \tn % Row 0 \SetRowColor{LightBackground} checkout . & Undo uncommited changes \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} reset HEAD & Unstage files \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} reset -{}-soft HEAD\textasciicircum{} & Undo commit (to stage) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} reset -{}-hard HEAD\textasciicircum{} & Undo commit \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} revert \textless{}commit\textgreater{} & Revert existing commit \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{BRANCHES}} \tn % Row 0 \SetRowColor{LightBackground} branch -avv & List all branches with refs \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} branch \textless{}name\textgreater{} {[}\textless{}commit\textgreater{}{]} & Create branch (at \textless{}commit\textgreater{}) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} checkout -b \textless{}branch\_name\textgreater{} & Create \& checkout new branch \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} checkout \textless{}branch\textgreater{} {[}file{]} & Checkout workspace (or file) \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} branch -m \textless{}new\_branch\_name\textgreater{} & Rename current branch \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} branch -d|-D \textless{}branch\textgreater{} & Delete merged/unmerged branch \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{MERGE}} \tn % Row 0 \SetRowColor{LightBackground} merge \textless{}with\_branch\textgreater{} & Merge branch (default: fast-forward) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} merge \textless{}with\_branch\textgreater{} -{}-no-ff & Merge branch (no fast-forward) \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{REBASE}} \tn % Row 0 \SetRowColor{LightBackground} rebase \textless{}new\_root\_commit\textgreater{} & Rebase current branch \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} rebase -i \textless{}start\_commit\textgreater{} & Interactive rebase \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} rebase -i HEAD\textasciitilde{}n & Interactive rebase (last n commits) \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.72 cm} x{3.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{REMOTES}} \tn % Row 0 \SetRowColor{LightBackground} remote -v & Show all remotes \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} remote add \textless{}name\textgreater{} \textless{}url\textgreater{} & Add remote \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} remote remove \textless{}name\textgreater{} & Remove remote \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{REMOTE BRANCHES}} \tn % Row 0 \SetRowColor{LightBackground} fetch {[}\textless{}remote\textgreater{}{]} & Get remote changes \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} pull {[}\textless{}remote\textgreater{}{]} & Get \& merge remote changes \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} pull -{}-rebase {[}\textless{}remote\textgreater{}{]} {[}\textless{}branch\textgreater{}{]} & Get \& rebase on remote changes \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} push {[}\textless{}remote\textgreater{}{]} {[}\textless{}branch\textgreater{}{]} {[}-f{]} & Push local branch to remote \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} push -n & Dry-run push \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} remote prune origin & Clean all old remote branch references \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{RESET}} \tn % Row 0 \SetRowColor{LightBackground} reset \textless{}mode\textgreater{} {[}\textless{}commit\textgreater{}{]} & Reset current branch to \textless{}commit\textgreater{} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} reset -{}-soft HEAD\textasciicircum{} & Undo commit \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} reset HEAD\textasciitilde{}n & Undo last n commits \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{-{}-soft - do not touch working tree/index \newline -{}-mixed - resets index \newline -{}-hard - resets working tree \& index} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{CHERRY-PICK}} \tn % Row 0 \SetRowColor{LightBackground} cherry-pick \textless{}commit\textgreater{} & Apply already-existing change \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} rebase -{}-onto \textless{}base\textgreater{} \textless{}start\textasciicircum{}\textgreater{} \textless{}end\textgreater{} & Apply set of already-existing changes \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{STASH}} \tn % Row 0 \SetRowColor{LightBackground} stash & Stash workdir \& index \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} stash list & List stashes \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} stash pop {[}-{}-index{]} & Apply \& delete stash \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} stash apply {[}-{}-index{]} & Apply stash \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} stash pop {[}stash@\{n\}{]} & Apply \& delete n-th stash \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} stash drop {[}stash@\{n\}{]} & Remove n-th or latest stash \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} stash clear & Remove all stashes \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} stash branch {[}\textless{}new\_branch\textgreater{}{]} & Create branch from a stash \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.36 cm} x{2.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{TAGS}} \tn % Row 0 \SetRowColor{LightBackground} tag & Liast tags \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} tag \textless{}tagname\textgreater{} {[}\textless{}commit\textgreater{}{]} & Add lightweight tag \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} tag -a \textless{}tagname\textgreater{} {[}-m "Tag message"{]} & Add annotated tag \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} tag -d \textless{}tagname\textgreater{} & Remove tag \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} push \textless{}remote\textgreater{} \textless{}tagname\textgreater{} & Push tag \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} push \textless{}remote\textgreater{} -{}-tags & Push with all tags \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} push \textless{}remote\textgreater{} :\textless{}tagname\textgreater{} & Remove remote tag \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{BLAME}} \tn % Row 0 \SetRowColor{LightBackground} blame \textless{}file\textgreater{} {[}-L start,stop{]} & Check who modified file (lines start-stop) \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.04 cm} x{2.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{REFLOG}} \tn % Row 0 \SetRowColor{LightBackground} reflog & Show history of HEAD \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} branch \textless{}new\_branch\_name\textgreater{} \textless{}lost\_commit\textgreater{} & Recover deleted branch \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.6 cm} x{6.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{CLEAN}} \tn % Row 0 \SetRowColor{LightBackground} gc & Manually clean garbage objects \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} clean -fd & Remove not tracked files and folders \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.72 cm} x{3.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{BISECT}} \tn % Row 0 \SetRowColor{LightBackground} bisect start \textless{}bad\_commit\textgreater{} \textless{}good\_commit\textgreater{} & Init bisect \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} bisect run test\_script.sh & Run automated binary-search \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Error code 125 to skip current branch} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}