main.tex 3.97 KB
 Joe Rackham committed Mar 23, 2020 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 \documentclass[8pt]{article} \usepackage[portrait, margin=1in]{geometry} \usepackage{float} \usepackage{rotating} \title{Git Guide} \author{Joe Rackham} \date{} \begin{document} \maketitle \section{Getting Started} \subsection{Creating a repo} \begin{itemize} \item \texttt{git init *dir\_name*} creates a new directory suitable to work with git \item \texttt{git init} converts an un-versioned directory into one usable with git \end{itemize} \section{Managing Git} \subsection{Configuring} \begin{itemize} \item \texttt{git config} is used to set configuration variables on a global or local level \item These variables are listed in \texttt{.gitconfig} text files. \item \texttt{--local} and \texttt{--global} are used to specify the visibility level; local is default \item \texttt{git config *var*} with report the var \texttt{git config *var* *value*} will update it \end{itemize} \begin{tabular}{|c|c|} \hline user.email & User's email address \\ \hline core.editor & Editor to open if input is required \\ \hline colour.ui & Used to adjust terminal output colouring \\ \hline \end{tabular} \subsection{Aliases} \begin{itemize} \item \texttt{git config alias.*abv* *cmd*} creates an alias for a command in the git config \item Note that the alias can't include the \texttt{git} command \end{itemize} \section{Branching \& Merging} \subsection{Creating a new branch} \begin{itemize} \item \texttt{git branch *bname*} creates a new branch \item \texttt{git checkout *bname*} begins working on that branch \item The first push has form \texttt{git push origin *orig\_branch*} to set the upstream for the branch \end{itemize} \subsection{Fast-Forward Merging} Can ONLY be use when there is a linear path to the branch head from the parent head: \begin{verbatim} git checkout *parent_branch* git merger *child_branch* \end{verbatim} \section{Workflow} \subsection{Committing} \begin{itemize} \item \texttt{git resest} will reset the changes staged for a commit \item The \texttt{--ammend} option will update the previous commit instead of creating a new one \end{itemize} \subsection{Stashing} \begin{itemize} \item \texttt{git stash} will store all changes made since the last commit for a later time \item \texttt{git stash pop} will restore these changes and remove them from the stash \item \texttt{git stash apply} will restore the changes and keep them in the stash \item Stashing ignores un-tracked and ignored files \item \texttt{git stash save *msg*} will stash changes with an annotation \end{itemize} \subsection{Tracking Changes} \begin{itemize} \item \texttt{git log} details recent changes to the repo \item \texttt{git blame} identifies the author associated with a specific committed line \end{itemize} \subsection{Undoing Changes} Checkout: \begin{itemize} \item \texttt{git checkout *hash*} sets the working state to that of a previous commit, the head pointer isn't moved \item This puts us in a detached HEAD state where we aren't working on any branch \item \texttt{git checkout -b *new\_bname*} will move any work we do to a new branch so it is not garbage collected \end{itemize} Revert: \begin{itemize} \item \texttt{git revert HEAD} will create a new commit with the inverse of the last commit \end{itemize} Reset: \begin{itemize} \item \texttt{git reset --hard} removes the previous commit from the history \end{itemize} \subsection{Maintenance} \begin{itemize} \item \texttt{git clean} will delete any un-tracked files; option \texttt{-n} can be used to do a dry-run Joe Rackham committed Mar 23, 2020 105 \item \texttt{git rm} removes a file from the working directory and the git index Joe Rackham committed Mar 23, 2020 106 107 108 109 110 111 112 113 \end{itemize} \subsection{Rewriting History} \begin{itemize} \item \texttt{git rebase} facilitates changing multiple or older commits \item Public commits should never be rebased \item \texttt{git squash} uses rebasing to combine multiple commits into one for a clean history \end{itemize} Joe Rackham committed Mar 23, 2020 114 115 116 117 \end{document}