Updates to «branches»

This commit is contained in:
Kenneth John Odle 2024-07-05 15:28:18 -04:00
parent f984737c9c
commit a40f2101da
3 changed files with 65 additions and 3 deletions

View File

@ -384,7 +384,7 @@ Dependency hell is suppposed to be a thing of the past, so I'm not quite sure wh
It's possible that the snap was configured wrong. It's also possible that I borked\footnote{I.e., I misconfigured or broke something.} something without realizing it when I was doing something else. (I do have a tendency to tinker with things under the hood.) Unlike the days of old I did not have to spend hours or days trying to figure this out. A couple of quick web searches got me up and running again.
\chapter{A \texttt{git} Workflow}
\chapter{A \texttt{git} Primer}
\lettrine[lines=2, loversize=0.2, findent=2mm, nindent=1mm, image=true]{git-icon}{} Git is version control software. That is, it allows you to record and track changes to a set of files over time. You can then compare different revisions or even revert some files or the entire project back to a previous version.
@ -456,7 +456,15 @@ If we're happy with the files we've staged, we can now commit them by using \tex
\section{Branches}
If you want to experiment, the best way to do that is to create a \textit{branch}.
If you want to experiment, the best way to do that is to create a \textit{branch}. To do that, just use \texttt{git branch <name>}. To move to that branch, you check it out\footnote{For a visual depiction, see, \kref{https://www.youtube.com/watch?v=8qxDBiiVjlQ}{https://www.youtube.com/watch?v=8qxDBiiVjlQ}.} using \texttt{git branch checkout <name>}.
Of course, there's a shortcut to this. We can use
\input{include/checkout}
which creates a branch called <name> and moves us to it automatically.
\section{Remote Repositories}
@ -519,8 +527,37 @@ Running \texttt{git branch} again confirms that our branch has been renamed:
\subsection{Pushing Changes to a Remote Repository}
Okay, we have a local repository, we have a remote repository attached to that local repository, and our current branch on both repos have the same name. It's time to move our code from our local repository to our remote one. For that we use, \texttt{git push} <name of remote repo> <name of remote branch>. Since our remote is named ``ogit'' and our branch is named ``main'', the full command looks like this:
\input{include/push}
Git thought for a second, and produced output like this:
\begin{Verbatim}[breaklines=true]
Enumerating objects: 3414, done.
Counting objects: 100% (3414/3414), done.
Delta compression using up to 4 threads
Compressing objects: 100% (1077/1077), done.
Writing objects: 100% (3414/3414), 3.01 MiB | 1.69 MiB/s, done.
Total 3414 (delta 2327), reused 3414 (delta 2327), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To https://git.kjodle.net/kjodle/Apollo-11
* [new branch] main -> main
\end{Verbatim}
That really did take only about 1 second to push 3.1 MiB\footnote{That's not a typo. MiB stands for a \texttt{mebibyte}. See ``The Later Salad Days'' in issue \#2 for more information.} of data. One nice thing about Git is that it is remarkably fast.
Here's the cool thing about Git: if you visit that original repository that I cloned on GitHub, you'll see that it has 547 commits. If you then visit the repository I created at \kref{https://git.kjodle.net/kjodle/Apollo-11}{https://git.kjodle.net/kjodle/Apollo-11}, you'll see that it also has 547 commits.
This is one of the nice things about Git: when you clone that remote repository, you are getting \textit{everything} associated with that repo. Other version control applications just checkout the most recent version. Hence the term ``clone'' rather than ``checkout''.
For what it's worth, you can have multiple remotes. I can create a remote repository on GitHub, clone it to my local machine, then create a remote somewhere else and add that remote to my local repo. To keep both remotes up to date with local changes, you'll need to push twice, once with \texttt{git push remote1 main} and again with \texttt{git push remote2 main}.
\section{Summary of Git Commands}
One of my favorite aspects of Git is that it's fairly intuitive to understand and start using right out of the box, but it's also robust enough to meet the needs of large teams and organizations. What I've done in the following table is to summarize the commands I've used in this primer, along with examples where appropriate. I've also included a few commands in this table that you probably won't use unless you are collaborating with others which I haven't discussed because it's outside the range of my experience. But I did want to include them to make the table a little more complete.
\begin{longtblr}
[
caption = {Summary of Git Commands},
@ -545,7 +582,16 @@ Command & Purpose {\& Example, if applicable} \\
\texttt{git push} & {Pushes a commit from a local repo to a remote repo \\ \texttt{git push} <name of remote repo> <name of remote branch> } \\
\texttt{git remote} & {Show only the names of remote repos \\ \texttt{git remote} } \\
\texttt{git remote -v} & {Show the names and URLs of remote repos \\ \texttt{git remote -v} } \\
\texttt{} & { -{}- \\ \texttt{} } \\
\texttt{git branch} & Show all branches (the current has an asterisk) \\
\texttt{git branch -{}-show-current} & Show only the current branch \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
\texttt{} & { \\ \texttt{} } \\
@ -797,6 +843,16 @@ The easy way around this is to write up those code samples in an independent \te
Also, there is a similar command (\texttt{include}) that works in a similar way, but adds a pagebreak before and after the included text. This is pretty handy if you are working on a longer document. For more information, see \kref{https://tex.stackexchange.com/questions/246/when-should-i-use-input-vs-include}{https://tex.stackexchange.com/questions/246/when-should-i-use-\\input-vs-include}.
\subsection{Ligatures and \LaTeX{} }
I have a table of basic Git commands on page \pageref{tb:gitcommsum}. One of the commands is \texttt{git -{}-version}. Notice that ``version'' has two hypens in front of it, as is typical with full-word bash options. But just typing two hypens didn't display two hypens, it displayed a single hyphen. I was momentarily confused.
What I forgot is that \LaTeX{} has a habit of collapsing multiple hyphens into ligatures. Two hyphens get converted to an en-dash, and three hypens get converted to an em-dash. But because this was displaying in a monotype font, it looked like an ordinary hyphen, even though it was an en-dash.
The fix for this was to use the \texttt{\{\}} token between the two hyphens. Without it, \LaTeX{} sees the two hyphens as a single entity, whereas with it, it sees them as two separate entities. Using this in my file \texttt{git -\{\}-version} gives me what I needed: \texttt{git -{}-version}.
Sometimes the simplest things are the easiest ones to forget.
\section{What I Learned About Other Things While Creating This Issue}

3
005/include/checkout.tex Normal file
View File

@ -0,0 +1,3 @@
\begin{Verbatim}[]
$ git checkout -b <name>
\end{Verbatim}

3
005/include/push.tex Normal file
View File

@ -0,0 +1,3 @@
\begin{Verbatim}[]
$ git push ogit main
\end{Verbatim}