\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{TME520 (TME520)} \pdfinfo{ /Title (git-everyday-use.pdf) /Creator (Cheatography) /Author (TME520 (TME520)) /Subject (GIT - Everyday use 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}{37A351} \definecolor{LightBackground}{HTML}{F2F9F4} \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 - Everyday use Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{TME520 (TME520)} via \textcolor{DarkBackground}{\uline{cheatography.com/20978/cs/22547/}}} \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}TME520 (TME520) \\ \uline{cheatography.com/tme520} \\ \uline{\seqsplit{tme520}.com} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 26th April, 2020.\\ Updated 2nd April, 2021.\\ 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{1.6 cm} x{6.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Key concepts}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{HEAD}} & Head is your current branch. You can see what HEAD points to by typing `cat .git/HEAD`, \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Remote}} & Remotes are non-local repositories you can interact with (push/pull). The default remote is {\emph{origin}} (you can see that using `git remote -v`). \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} {\bf{Branch}} & Branches are a way of safely work on new features without messing other peoples work (one feature, one branch). \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} {\bf{Commit}} & A commit is a change or a set of changes you wish to register and save. \tn % Row Count 15 (+ 3) \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}{Repositories}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Create a local repository}} & \{\{nobreak\}\}mkdir ./my\_repo \&\& cd ./my\_repo \&\& git init \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Clone a repository from GitHub}} & \{\{nobreak\}\}git clone \seqsplit{https://github.com/TME520/etm.git} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Clone a specific branch from a repo}} & \{\{nobreak\}\}git clone -b development \seqsplit{https://github.com/TME520/etm.git} \tn % Row Count 10 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Branches}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{List branches}} & git branch & git branch -{}-list \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Clone a specific branch}} & \{\{nobreak\}\}git clone -b \textless{}branch\textgreater{} \textless{}remote\_repo\textgreater{} & git clone -b development \seqsplit{git@github.com:user/myproject.git} \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} {\bf{Switch to an existing branch}} & git checkout \textless{}branch\textgreater{} & git checkout \seqsplit{feat/robert/add-pub-holidays-2020} \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} {\bf{Switch to a new branch}} & git checkout -b \textless{}new\_branch\textgreater{} & git checkout -b \seqsplit{conf/marcel/use-EditorConfig} \tn % Row Count 15 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Push changes to a remote branch}} & git push origin \textless{}branch\textgreater{} & git push origin \seqsplit{fix/patrick/remove-parasite-chars-from-config-file} \tn % Row Count 21 (+ 6) % Row 5 \SetRowColor{white} {\bf{Delete a branch}} & git branch -d \textless{}branch\textgreater{} & git branch -d \seqsplit{feat/raja/count-api-failures} \tn % Row Count 25 (+ 4) % Row 6 \SetRowColor{LightBackground} {\bf{Integrate your feature branch to the main}} & git merge \textless{}branch\textgreater{} & git merge main \tn % Row Count 29 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{Using branches, several developers are able to work together on the same code base, the same project. \newline {\bf{git merge}} is not usually done manually, but is managed by your pull request system.} \tn \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}{Getting out of (mild) troubles}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Cancel untracked uncommited local changes}} & \{\{nobreak\}\}git reset -{}-hard \&\& git pull remote \textless{}remote\_branch\textgreater{} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Basic configuration}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Set your name}} & \{\{nobreak\}\}git config -{}-global user.name "John Doe" \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Set your email address}} & \{\{nobreak\}\}git config -{}-global user.email johndoe@example.com \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Set your default editor}} & \{\{nobreak\}\}git config -{}-global core.editor emacs \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Dot files}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{.gitignore}} & Specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \{\{nobreak\}\}{\emph{.gitattributes}} & Gives attributes (end of line type, diff type, merge type...) to certain files. \tn % Row Count 9 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Examples of {\emph{.gitignore}} files: \{\{link="https://github.com/github/gitignore"\}\}click here\{\{/link\}\} \newline Examples of {\emph{.gitattributes}} files: \{\{link="https://github.com/alexkaratarakis/gitattributes"\}\}click here\{\{/link\}\}} \tn \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}{Basic workflow}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Clone a repo}} & \{\{nobreak\}\}git clone \seqsplit{https://github.com/TME520/etm.git} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Create a new branch}} & \{\{nobreak\}\}git checkout -b \seqsplit{conf/yu/add-api-endpoints-to-monitoring} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{Check repo status and current branch}} & git status \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} {\bf{Add changes to next commit (track files)}} & git add -A \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{Commit with a message}} & \{\{nobreak\}\}git commit -m "Sometimes dogs are grey" \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} {\bf{Refresh current local branch with remote branch}} & \{\{nobreak\}\}git pull origin development \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{Push changes to remote}} & \{\{nobreak\}\}git push origin \seqsplit{conf/yu/add-api-endpoints-to-monitoring} \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{git push}} uploads your commits to the remote repository. \newline {\bf{git pull}} is a combination of git fetch and git merge. It gets the updates from remote repository and applies the latest changes to your local.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Commits}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Add one file to a future commit}} & git add \textless{}file\textgreater{} & git add benchmark.c \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Add all files to a future commit}} & git add -A & \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Commit with a message}} & \{\{nobreak\}\}git commit -m "\textless{}message\textgreater{}" & git commit -m "Initial commit" \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} {\bf{Change the message of the latest commit}} & \{\{nobreak\}\}git commit -{}-amend -m "\textless{}new\_message\textgreater{}" & git commit -{}-amend -m "Beautiful commit" \tn % Row Count 13 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Cancel a commit}} & git log  -{}- oneline & \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} & git revert \textless{}commit\_id\textgreater{} & \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{Git commits are checkpoints in the development process which you can go back to later if needed. \newline {\bf{Git commit saves your changes only locally.}} \newline {\bf{git revert}} won't delete the commit, it will instead create a new one cancelling the other.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}