\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{KYS1477} \pdfinfo{ /Title (git.pdf) /Creator (Cheatography) /Author (KYS1477) /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}{EB712A} \definecolor{LightBackground}{HTML}{FDF6F1} \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}{KYS1477} via \textcolor{DarkBackground}{\uline{cheatography.com/186487/cs/39697/}}} \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}KYS1477 \\ \uline{cheatography.com/kys1477} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 29th March, 2024.\\ 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Principles}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create a git repository for every new project} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Create a new branch for every new feature} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Branch early, and branch often} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{SSH keys are how we securely communicate btw our computer and GitLab} \tn % Row Count 5 (+ 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}{Typical Workflow}} \tn % Row 0 \SetRowColor{LightBackground} git clone \textless{}repo\textgreater{} & clone repo located at \textless{}repo\textgreater{} onto local machine, clone with SSH \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} cd my\_project & after git clone, go to the directory, before using all the git commands \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} git checkout -b my\_branch \seqsplit{origin/remote\_branch1} & create and checkout my\_branch, that is tracking remote\_branch1 \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{git add \textless{}file\_name\textgreater{}} \tn % Row Count 13 (+ 1) % Row 4 \SetRowColor{LightBackground} git commit -m "message" & commit the change to my\_branch \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} git pull & update local my\_branch with remote commits and update all remote tracking branches \tn % Row Count 20 (+ 5) % Row 6 \SetRowColor{LightBackground} git merge \seqsplit{origin/remote\_branch2} & merge remote\_branch2 with the branch that you are currently on (my\_branch) \tn % Row Count 24 (+ 4) % Row 7 \SetRowColor{white} git push origin & push the branch that you are on (my\_branch) to origin (remote repo) \tn % Row Count 28 (+ 4) % Row 8 \SetRowColor{LightBackground} (create a merge request on GitLab UI) & rmb to change target branch \tn % Row Count 30 (+ 2) \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}{Typical Workflow 2 - PyCharm}} \tn % Row 0 \SetRowColor{LightBackground} git pull & before pushing your changes, sync with the remote and make sure your local copy of the repository is up to date to avoid conflicts \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} git push & push changes from the current branch \tn % Row Count 9 (+ 2) % Row 2 \SetRowColor{LightBackground} define remote and select target branch & click on Define remote link (appears when there is no remotes in the repository), click on the branch name \tn % Row Count 15 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\seqsplit{https://www.jetbrains.com/help/pycharm/commit-and-push-changes.html\#force-push}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pushing and merging code change}} \tn % Row 0 \SetRowColor{LightBackground} git add \textless{}file\_name\textgreater{} / git add -{}-all & add the file to the staging area \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git commit -m "short\_msg" & takes a permanent snapshot of the current state of your repository that is associated with a unique identifier \tn % Row Count 8 (+ 6) % Row 2 \SetRowColor{LightBackground} git push origin \textless{}branch\_name\textgreater{} & pushes a local branch(es) to a remote repository (origin - the conventional shorthand name of the url for the remote repository) \tn % Row Count 15 (+ 7) % Row 3 \SetRowColor{white} git checkout main & checkout the default branch of your repo \tn % Row Count 17 (+ 2) % Row 4 \SetRowColor{LightBackground} git merge \textless{}branch\_name\textgreater{} & merge your branch into the default branch \tn % Row Count 19 (+ 2) % Row 5 \SetRowColor{white} git push & push the changes \tn % Row Count 20 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\seqsplit{https://docs.gitlab.com/ee/tutorials/make\_first\_git\_commit/}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.08 cm} x{5.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Check}} \tn % Row 0 \SetRowColor{LightBackground} git status & list which files are staged, unstaged, and untracked \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git branch & list all of the branches in your repo \{\{nl\}\}-r to list the remote branches \{\{nl\}\}-a to see all branches \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} git diff & show unstaged changes between your index and working directory \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} git log & list the version history for the current branch \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} git ls-files & check which files are in your staged area \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} git branch -vv & check tracking branches \tn % Row Count 15 (+ 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}{Useful Commands}} \tn % Row 0 \SetRowColor{LightBackground} git init & creates a new git repository, use this command while inside the project folder, this will create a .git folder \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} git branch \textless{}branch\_name\textgreater{} & create a branch \tn % Row Count 8 (+ 2) % Row 2 \SetRowColor{LightBackground} git checkout \textless{}branch\_name\textgreater{} & change to the branch \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} git branch -u \seqsplit{origin/remote\_branch} & -u = -{}-set-upstream \{\{nl\}\}set the tracking branch to be remote\_branch \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} git fetch & pulls in all the commits from your remote but doesn't make any changes to your local files (will overwrite your current files) \tn % Row Count 21 (+ 7) % Row 5 \SetRowColor{white} git branch -m new\_branch\_name & rename a branch \tn % Row Count 23 (+ 2) % Row 6 \SetRowColor{LightBackground} git branch -{}-delete branch\_name & delete a branch \tn % Row Count 25 (+ 2) % Row 7 \SetRowColor{white} git stash apply stash@\{n\} & restore a git stash, run git stash list to see the list \tn % Row Count 28 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{More info on setting upstream \seqsplit{https://devconnected.com/how-to-set-upstream-branch-on-git/} \newline Origin is the name which git gives to the remote repo that you cloned from} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Making Changes}} \tn % Row 0 \SetRowColor{LightBackground} git reset -{}-hard & to discard all local changes (new files created in the local Git workspace that have never been added to the index will remain in the project folder after the hard reset) \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} git reset \textless{}file\_name\textgreater{} & undo git add - remove staged version of the file \tn % Row Count 12 (+ 3) % Row 2 \SetRowColor{LightBackground} git reset HEAD\textasciitilde{}1 & undo the prev commit \tn % Row Count 13 (+ 1) % Row 3 \SetRowColor{white} git revert HEAD & undo the prev commit (for remote branch) \tn % Row Count 15 (+ 2) % Row 4 \SetRowColor{LightBackground} git commit -{}-amend -m "new message" & edit commit msg \tn % Row Count 17 (+ 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}{To be classified}} \tn % Row 0 \SetRowColor{LightBackground} git rebase \textless{}branch\_name\textgreater{} & copy our work from the current branch we are on to branch\_name \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} git checkout \textless{}branch\_name\textgreater{}\textasciicircum{} & move up one commit of branch \_name \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} git checkout HEAD\textasciicircum{} (\textasciitilde{}4) & move upwards in a commit tree \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} git branch -f \textless{}branch\_name\textgreater{} \textless{}commit\_hash\textgreater{} & reassign a branch to a commit \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} git stash & takes your uncommitted changes (both staged and unstaged), saves them away for later use \tn % Row Count 16 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}