\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{\_\_i-Sage\_\_ (\_\_i-Sage\_\_)} \pdfinfo{ /Title (git-commands-cheat-sheet.pdf) /Creator (Cheatography) /Author (\_\_i-Sage\_\_ (\_\_i-Sage\_\_)) /Subject (git\_commands\_cheat\_sheet 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}{5C1313} \definecolor{LightBackground}{HTML}{F9F7F7} \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\_commands\_cheat\_sheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{\_\_i-Sage\_\_ (\_\_i-Sage\_\_)} via \textcolor{DarkBackground}{\uline{cheatography.com/189705/cs/39545/}}} \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}\_\_i-Sage\_\_ (\_\_i-Sage\_\_) \\ \uline{cheatography.com/i-sage} \\ \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 July, 2023.\\ Updated 13th July, 2023.\\ 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{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands for version tagging}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git tag`}} & List all available tags in Git \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{`git tag -l {[}tag\_number{]}`}} & search for tags with the particular tag\_number \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{`git tag -a {[}tag\_number{]} -m {[}message{]}`}} & creates an annotated tag with an optional tagging message \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{`git show {[}tag\_number{]}`}} & shows the tagger information \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{`git tag {[}tag\_number{]}-lw`}} & creates a lightweight tag \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} {\bf{`git tag -a {[}tag\_number{]} {[}part\_of\_check\_sum{]}`}} & tags the commit after you've moved passed them \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{`git push origin {[}tag\_number{]}`}} & push version\_number to shared server after you have created them. \tn % Row Count 19 (+ 4) % Row 7 \SetRowColor{white} {\bf{`git push origin -{}-tags`}} & push tags to shared server \tn % Row Count 21 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{`git checkout -b {[}branch\_name{]} {[}tag\_name{]}`}} & put a version of the repository in your working directory that looks like a specific tag \tn % Row Count 26 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{By default, the git push command doesn't transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches, you can run git push origin "tag\_name"} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands to clone and create repositories}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git init`}} & Initializes a new git repository in the current directory \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{`git clone url`}} & Clone an existing Git repository located at in the current directory \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{`git clone url directory\_name`}} & Clone an existing Git repository located at in directory\_name \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands to check status}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git status` }} & used to determine which files are in which state \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{`git status -s`}} & the short and compact representation of git status \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands for removing and renaming files}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git rm "file\_name"`}} & Removes the file from your tracked files and the working directory \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{`git rm -{}-cached "file\_name"`}} & Removes the files from your tracked files but keeps the file in the working directory \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} {\bf{`git mv "file\_from" "file\_to"`}} & Renames the file form "file\_from" to "file\_to" \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands for undoing things}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git reset {[}file\_name{]}`}} & used to unstage the "file\_name \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{`git checkout -{}- {[}file\_name{]}`}} & reverts a file to the previous version \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands for staging files}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git add file\_name`}} & Stage file\_name for commit \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{`git add -A`}} & Stage all modified or new files for commit \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{`git reset file\_name`}} & Unstage file\_name \tn % Row Count 6 (+ 2) \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}{git commands for working with remotes}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git remote add "name" "url"`}} & Create a new remote named "name" for the repository at "url" \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{`git fetch "remote"`}} & Download all changes from "remote", but don't integrate into current branch \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{`git merge "remote"/"branch"`}} & Merge "remote{]}/{[}branch" into current branch \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} {\bf{`git push "remote" "branch"`}} & Push local changes in "branch" to "remote"/"branch" \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{`git pull "remote" "branch"`}} & Fetch and merge all changes from "remote"/"branch" into current branch \tn % Row Count 16 (+ 4) \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}{git commands for commiting changes}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git commit -m "message"`}} & Commit staged changes with "message" describing changes \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{`git commit -{}-amend`}} & Edit the previous commit message or contents \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{`git commit -a -m "message"`}} & Stages all already tracked files and commits them \tn % Row Count 8 (+ 3) \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}{git commands for branching and merging}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git remote add "name" "url"`}} & Create a new remote named "name" for the repository at "url" \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{`git branch "name"`}} & Create a new branch named "name" \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{`git checkout "name"`}} & Switch to branch named "name" \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} {\bf{`git merge "branch"`}} & Merge "branch" into current branch \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{`git merge -{}-no-ff "branch"`}} & Merge "branch" into current branch, keeping branch history \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git commands for inspections and differences}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`git log`}} & View the commit history of the current branch \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{`git log "branch"`}} & View the commit history of "branch" \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{`git log -{}-stat`}} & Prints below each commit entry a list of modified files, how many files where changed, and how many lines in those files where added or removed \tn % Row Count 12 (+ 7) % Row 3 \SetRowColor{white} {\bf{`git log -{}-pretty=online`}} & This option changes the log output to formats other than the default \tn % Row Count 16 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{`git log -{}-graph`}} & Display an ASCII graph of the branch and merge history beside the log output \tn % Row Count 20 (+ 4) % Row 5 \SetRowColor{white} {\bf{`git diff`}} & View unstaged changes between the current state of the code and the last commit \tn % Row Count 24 (+ 4) % Row 6 \SetRowColor{LightBackground} {\bf{`git diff -{}-cached`}} & View staged changes between last commit and the current state of the code \tn % Row Count 28 (+ 4) % Row 7 \SetRowColor{white} {\bf{`git diff "branch1" "branch2"`}} & View differences between "branch1" and "branch2" \tn % Row Count 31 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}