Minor updates to Git chapter

This commit is contained in:
Kenneth John Odle 2024-08-08 12:48:41 -04:00
parent f7ad3618f1
commit 6d8b8a5400

View File

@ -470,7 +470,7 @@ It's possible that the snap was configured wrong. It's also possible that I bork
\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.
What I'm going to do here is describe how I understand and use Git. I am far from a power-user or expert in Git, so I may get some things wrong. This is definitely not intended to be at all comprehensive, but more just a way for you to get your feet wet.
What I'm going to do here is describe how I understand Git. I am far from a power-user or expert in Git, so I may get some things wrong. This is definitely not intended to be at all comprehensive, but more just a way for you to get your feet wet. My goal is to encourage you to think about how you might benefit from using Git.
\section{What Git Can Do For You}
@ -486,7 +486,7 @@ If this is your first exposure to version control software you'll make faster pr
\paragraph{Concept Two: The basic time unit of Git is a \textit{commit}.} A commit is simply a snapshot of where your project stands at any given moment. When you make a commit, it's like taking a picture of your project at that particular moment.
\paragraph{Concept Three: The basic space unit of Git is a \textit{repository}.} All those commmits have to live somewhere, and a repository is just a place where all those commits exist. Repositories (or ``repos'' for short) can be \textit{local}—that is, they exist on your computer only—or they can be \textit{remote}—meaning that can live on other computers somewhere else. That ``somewhere else'' is usually a publicly available server. You can create your own\footnote{You can see mine at \kref{https://git.kjodle.net/}{https://git.kjodle.net/}, for example.} or you can get an account at someplace like Gitlab\footnote{\kref{https://gitlab.com/}{https://gitlab.com/}} which is for-profit and wants your money, or Github\footnote{\kref{https://github.com/}{https://github.com/}} which is now owned by Microsoft and wants your soul.
\paragraph{Concept Three: The basic space unit of Git is a \textit{repository}.} All those commmits have to live somewhere, and a repository is just a place where all those commits exist. Repositories (or ``repos'' for short) can be \textit{local}—that is, they exist on your computer only—or they can be \textit{remote}—meaning that can live on other computers somewhere else. That ``somewhere else'' is usually a publicly available server. You can create your own\footnote{You can see mine at \kref{https://git.kjodle.net/}{https://git.kjodle.net/} for example.} or you can get an account at someplace like Gitlab\footnote{\kref{https://gitlab.com/}{https://gitlab.com/}} which is for-profit and wants your money, or Github\footnote{\kref{https://github.com/}{https://github.com/}} which is now owned by Microsoft and wants your soul.
You can work with a local repository only, or you can decide to work with one or more remote repositories. The choice is up to you.
@ -504,6 +504,8 @@ Git is a command line based technology. Yes, there are GUIs out there for Git, a
In general, I advise against using any type of GUI with Git. For one thing, Git is fairly easy to manage from the command line, so using a GUI just adds a level of abstraction that we don't really need. For another, the command line is forever, but GUIs come and go. If your GUI gets to a point where it's development is discontinued, or it decides to adopt a subscription model that you can't afford, you're screwed.
A GUI can also high what Git is actually doing, meaning that might end up with less understanding of Git than you would by working on the command line.
\section{Local Repositories}
Let's start with local repositories. Assuming you have a folder full of files you want to track using Git, open a terminal window in that location (which is now called your ``working directory'') and type \texttt{git init}. Congratulations! You now have a local Git repo!
@ -514,7 +516,7 @@ Technically, the \texttt{.git} directory is the actual repository. But most peop
We haven't made any commits yet, though. All we have are files in our working directory. To make a commit, we need to \textit{stage} our files by using the \texttt{git add} command. You can do this a couple of different ways: we can either list each file one by one (i.e., \texttt{git add file1.txt file2.txt}) or we can just add them all in a single go by using the \texttt{*} wildcard (\texttt{git add *} which will \textit{not} add invisible files, or \texttt{git add -A} which \textit{will} add invisible files).
Now that we've added our files, they are considered to be \texttt{staged}, which means that they are ready to commit. We can make a commit now, or we can modify or create new files, and then add them as well. The choice is yours—Git doesn't penalize you either way. Personally, I prefer to make many smaller commits to avoid losing data.
Now that we've added our files, they are considered to be \texttt{staged}, which means that they are ready to commit. We can make a commit now, or we can modify or create new files, and then add them as well. The choice is yours—Git doesn't penalize you either way. Personally, I prefer to make many smaller commits to avoid losing data (and metadata).
If we're happy with the files we've staged, we can now commit them by using \texttt{git commit -m "<commit message>"}. Note that we have to add a commit message. This can be anything you like, but it helps to make it something that will be useful down the road like ``updated chapter three''. You'll get some miscellaneous messages about what Git is doing and then it is done. You've created your first commit, and all of your staged files are now \texttt{committed}.\footnote{You can also make this process even more efficient by creating some bash alias for the various Git commands. See ``More Fun with bash'' in issue \#4.}
@ -526,7 +528,7 @@ Of course, there's a shortcut to this. We can use
\input{include/checkout}
which creates a branch called <branchname> and moves us to it automatically.
which creates a branch called ``branchname'' and moves us to it automatically.
This is the point where we experiment and have fun on this branch without worrying about our main branch. Wouldn't it be nice if life were like this?\footnote{Gosh, I've mentioned this twice. There are lots of science fiction stories about this possibility. I guess it's time to go read one. Or write one.}
@ -644,7 +646,9 @@ Go home and go into your local repo. Open a terminal in that directory and use t
\input{include/pull}
What does \texttt{git pull} do? It's a combination of two Git commands: \texttt{fetch} and \texttt{merge}. \texttt{git fetch} gets the change history of the tracked remote and branch, whereas \texttt{git merge} combines the current branch with the specified branch. Your local repository will now look like your remote repository. You can write to your heart's content, push those changes, and call it a day. If you're back at the hospital waiting room again some time later, you can just repeat the process.\footnote{Again, for a visual depiction of this, please visit \kref{https://www.youtube.com/watch?v=FG1NrQYXjLU}{https://www.youtube.com/watch?v=\\FG1NrQYXjLU}.}
What does \texttt{git pull} do? It's a combination of two Git commands: \texttt{fetch} and \texttt{merge}.
\texttt{git fetch} gets the change history of the tracked remote and branch, whereas \texttt{git merge} combines the current branch with the specified branch. Your local repository will now look like your remote repository. You can write to your heart's content, push those changes, and call it a day. If you're back at the hospital waiting room again some time later, you can just repeat the process.\footnote{Again, for a visual depiction of this, please visit \kref{https://www.youtube.com/watch?v=FG1NrQYXjLU}{https://www.youtube.com/watch?v=\\FG1NrQYXjLU}.}
\section{Extra Files}
@ -687,6 +691,8 @@ Command & Purpose {\& Example, if applicable} \\
\texttt{git remote} & {Show only the names of remote repos \\ \texttt{git remote} } \\
\texttt{git remote -v} & {Show both the names and URLs of remote repos \\ \texttt{git remote -v} } \\
\texttt{git status} & Show which files have been staged and which files are waiting to be staged \\
\texttt{git status -s} & As above, but in short form \\
\texttt{git status -u} & As above, but only show untracked files \\
\texttt{git branch} & Show all branches (the current branch is labeled with an asterisk) \\
\texttt{git branch -{}-show-current} & Show only the current branch \\
\end{longtblr}