Skip to content

Commit da214be

Browse files
committed
added cloning using git command line client
1 parent 3ea9969 commit da214be

File tree

14 files changed

+129
-23
lines changed

14 files changed

+129
-23
lines changed

text/front/preface/preface.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ \chapter*{Preface}%
3737
%
3838
This book contains a lot of examples.
3939
You can find all of them in the repository \url{\programmingWithPythonCodeRepo}.
40-
You can clone this repository and play with these example codes.%
40+
You can clone this repository as discussed in \cref{sec:gettingExamples,sec:gitClone} and play with these example codes.%
4141
%
4242
\begin{sloppypar}%
4343
The text of the book itself is also available in the repository \url{\programmingWithPythonRepo}.

text/main/basics/gettingStarted/examples/examples.tex

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
\hsection{Getting the Examples from this Book}%
2+
\label{sec:gettingExamples}%
23
%
34
\begin{figure}%
45
\centering%
@@ -57,7 +58,7 @@
5758
On the website, you can directly download all the examples as illustrated in \cref{fig:downloadExamples}.
5859
First, you would click on the little downward facing triangle in the button \menu{Code}.
5960
This will open a small dialog \menu{Clone} in which you can click on the \menu{Download ZIP} button.
60-
This, in turn, enters the URL~\expandafter\url{\programmingWithPythonCodeRepo/archive/refs/heads/main.zip} into your browser's download queue.
61+
This, in turn, enters the \pgls{URL}~\expandafter\url{\programmingWithPythonCodeRepo/archive/refs/heads/main.zip} into your browser's download queue.
6162
A \texttt{zip}~archive is a single file that can contain other files and folders and can be opened by the standard file managers both on \ubuntu\ and \windows.
6263
Once downloaded, the archive contains all the examples that we use in our book.%
6364
\end{sloppypar}%
@@ -75,7 +76,8 @@
7576
%
7677
Once the repository has been downloaded, \pycharm\ may ask you whether you trust this project.
7778
After making sure that you indeed downloaded the examples for this book (and if you deem this code trustworthy), you can click \menu{Trust Project}, as \cref{fig:clone04trustProject}.
78-
Finally, as \cref{fig:clone05finished} shows, you can now see and play with and run all the examples in \pycharm.%
79+
Finally, as \cref{fig:clone05finished} shows, you can now see and play with and run all the examples in \pycharm.
80+
A more comprehensive discussion on how to clone repositories is given in \cref{sec:gitClone}.%
7981
%
8082
\endhsection%
8183
%

text/main/classes/dunder/dunder.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@
12631263

12641264
As example, let us create a simple API that allows us to write output in a subset of the \acrfull{XML} format~\cite{BPSMM2008EMLX1FE,K2019ITXJY,CH2013XFCAMLTMC}.
12651265
\pgls{xml} is a format for data interchange which was predominant in distributed systems the~2000s.
1266-
After that, it began to fade out in favor~\cite{A2020XLATDOEOL} of \pgls{json}~\cite{E2017SE4TJDIS,B2017TJONJDIF} and \pgls{yaml}~\cite{DNMAASBE2021YAMLYV1,K2019ITXJY,CGTYB2022YFFDCAIE}.
1266+
After that, it began to fade out in favor~\cite{A2020XLATDOEOL} of \pgls{json}~\cite{E2017SE4TJDIS,RFC8259} and \pgls{yaml}~\cite{DNMAASBE2021YAMLYV1,K2019ITXJY,CGTYB2022YFFDCAIE}.
12671267
It is still very relevant today, for example, as foundation of several document formats such as those used in LibreOffice~\cite{DF2024LTDF,GL2012LTSOOSSCBAFACSOL} and Microsoft~Word~\cite{MS2024MW,DR2019STFAWAUMW}, or as the basis for the SVG graphics format~\cite{DDGLMSWFJJ2011SVGSSE}.
12681268
If you are a bit familiar with web design, then you will find that \pgls{xml} looks a bit like HTML~\cite{HBFLDNOP2014HAVAAAFHAX}.%
12691269
%

text/main/controlFlow/exceptions/exceptions.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@
537537
To do so, we call the built-in function~\pythonilIdx{open}.
538538
We pass in the filename~\textil{"example.txt"} as first parameter.
539539
The second parameter, \pythonil{mode}\pythonIdx{open!mode}, is set to~\pythonil{"w"}, which means \inQuotes{open for writing.}
540-
The parameter \pythonil{encoding}\pythonIdx{open!encoding} is set to~\pythonil{"UTF-8"}\pythonIdx{UTF-8}, which defines that the text should be translated to binary form when it is stored in the file via the usual \pgls{utf8}~encoding~\cite{Y2003UATFOI1,ISOIEC106462020ITUCCSU}.
540+
The parameter \pythonil{encoding}\pythonIdx{open!encoding} is set to~\pythonil{"UTF-8"}\pythonIdx{UTF-8}, which defines that the text should be translated to binary form when it is stored in the file via the usual \pgls{utf8}~encoding~\cite{RFC3629,ISOIEC106462020ITUCCSU}.
541541
This is of no importance here and we will discuss this eventually later in the book.
542542

543543
Anyway, if opening the text file succeeds, we now have a variable~\pythonil{stream_out}, which is an instance of~\pythonilIdx{IO}.

text/main/ecosystem/git/gitClone/gitClone.tex

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
\hsection{Cloning git Repositories}%
2+
\label{sec:gitClone}%
23
%
34
The most fundamental activity you will encounter is \emph{cloning} repositories.
45
Under \git, this basically means to download the complete repository and its history to your machine.
@@ -12,5 +13,6 @@
1213
We here outline both approaches.%
1314
%
1415
\hinput{gitClonePycharm}{gitClonePycharm}%
16+
\hinput{gitCloneClient}{gitCloneClient}%
1517
%
1618
\endhsection%
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
\hsection{Cloning git Repositories with the git Client}%
2+
%
3+
\begin{figure}%
4+
\centering%
5+
%
6+
\subfloat[][%
7+
After opening the \ubuntu\ \linux\ \pgls{terminal} using \ubuntuTerminal, we enter the directory into which we want to download the repository. %
8+
We then type the command \bashil{git clone https://github.com/thomasWeise/databasesCode} and hit \keys{\enter}. %
9+
The option \bashil{--recurse-submodules} can be added just in case.%
10+
\label{fig:gitCloneClient1clone}%
11+
]{\includegraphics[width=0.78\linewidth]{\currentDir/gitCloneClient1clone}}%
12+
%
13+
\floatRowSep%
14+
%
15+
\subfloat[][%
16+
The process of cloning the repository begins.%
17+
\label{fig:gitCloneClient2cloning}%
18+
]{\includegraphics[width=0.78\linewidth]{\currentDir/gitCloneClient2cloning}}%
19+
%
20+
\floatRowSep%
21+
%
22+
\subfloat[][%
23+
Sometimes, there may be connectivity issues. %
24+
But do not fret if that happens\dots%
25+
\label{fig:gitCloneClient3error}%
26+
]{\includegraphics[width=0.78\linewidth]{\currentDir/gitCloneClient3error}}%
27+
%
28+
\floatRowSep%
29+
%
30+
\subfloat[][%
31+
{\dots}simply try again (and, if necessary, again and again). %
32+
Sometimes, it may make sense to switch the network, e.g., from using WLAN, instead connect your mobile phone to your computer using a USB cable and share the data connection of the mobile phone using USB tethering.%
33+
\label{fig:gitCloneClient4nextAttempt}%
34+
]{\includegraphics[width=0.78\linewidth]{\currentDir/gitCloneClient4nextAttempt}}%
35+
%
36+
\floatRowSep%
37+
%
38+
\subfloat[][%
39+
Eventually, it will work.%
40+
\label{fig:gitCloneClient5success}%
41+
]{\includegraphics[width=0.78\linewidth]{\currentDir/gitCloneClient5success}}%
42+
%
43+
\floatRowSep%
44+
%
45+
\subfloat[][%
46+
The repository has been downloaded and a new folder with the repository name (here:~\textil{databasesCode}) has appeared.%
47+
\label{fig:gitCloneClient6files}%
48+
]{\includegraphics[width=0.78\linewidth]{\currentDir/gitCloneClient6files}}%
49+
%
50+
\caption{Cloning a \git\ repository using the \git\ \pgls{client} application \bashil{git} in an \ubuntu\ \linux\ \pgls{terminal} and how to deal with connection errors.}%
51+
\label{fig:gitCloneClient}%
52+
%
53+
\end{figure}%
54+
%
55+
The most basic way to clone \git\ repositories is to use the \git\ \pgls{client} application.
56+
This is a command line tool that can be executed in a \pgls{terminal}.
57+
Here, we simply assume that you already have it installed the \git\ \pgls{client} program~\bashil{git}.
58+
59+
In \cref{fig:gitCloneClient}, we illustrate how the \git\ \pgls{client} program is used under \ubuntu\ \linux.
60+
Under Microsoft \windows, it will work analogously.
61+
First, we need to open a \pgls{terminal} window.
62+
Under \ubuntu\ \linux, we therefore press \ubuntuTerminal.
63+
Under \windows, we instead \windowsTerminal.
64+
We then enter the directory into which we want to download the repository using~\bashil{cd}.
65+
Notice that if we download a repository with the name~\textil{abc}, this will create a new directory named~\textil{abc} inside that current working directory.
66+
67+
We then type the command \bashil{git clone https://github.com/thomasWeise/databasesCode} and hit \keys{\enter}.
68+
Sometimes, repositories contain submodules.
69+
A submodules is basically a links to a specific state (commit) of \emph{another} repository.
70+
The files of the referenced commit of the other repository would then exist inside a directory of the repository that we want to clone.
71+
If we want to have a full copy of all the files, including the files referenced this way, we need to add the option \bashil{--recurse-submodules} to the \bashil{git} command.
72+
We do this in \cref{fig:gitCloneClient1clone} to be on the safe side for demonstration purpose (although the repository \textil{databasesCode} does \emph{not} have any submodule).
73+
74+
After we hit \keys{\enter}, the process of cloning the repository begins in \cref{fig:gitCloneClient2cloning}.
75+
Sadly, when we clone repositories using \pgls{HTTPS} \pglspl{URL} from \github, sometimes, there may be connectivity issues.
76+
I noticed that using the \pgls{SSH} \pglspl{URL} is much more reliable.
77+
An example for such an error is shown in \cref{fig:gitCloneClient3error}.
78+
79+
However, this is not a big problem.
80+
If such errors happen, you can simply try again after some time.
81+
I furthermore noticed that, often, changing your internet connection can solve the problem.
82+
Let's say that you are trying to clone the repository using your wired or wireless LAN and it does not work.
83+
Then it often helps to first switch of the network connection on your computer.
84+
On your mobile phone, you should also switch off wireless LAN and instead activate your mobile data connection.
85+
Then you can connect your mobile phone to your computer using a USB cable and select \emph{USB tethering} on your phone.
86+
This will share the mobile data connection with your computer.
87+
Then, simply try to clone the repository again, as shown in \cref{fig:gitCloneClient4nextAttempt}.
88+
The connection switching is just a quick work around.
89+
Often, \bashil{git clone} works at first attempt and, if not, works after you wait a minute or so.
90+
91+
Eventually, it will work, as shown in \cref{fig:gitCloneClient5success}.
92+
After the \bashil{git} command completes, the repository has been downloaded and a new folder with the repository name (here:~\textil{databasesCode}) has appeared.
93+
The \bash\ command \bashil{ls} lists the files in a directory.
94+
We see that the new directory contains the downloaded files in \cref{fig:gitCloneClient6files}.
95+
Here, we will not deal with the issue of \pglspl{virtualEnvironment}, as we discussed them in the previous section about cloning repositories using \pycharm.%
96+
%
97+
\FloatBarrier%
98+
\endhsection%
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

text/main/ecosystem/git/gitClone/gitClonePycharm/gitClonePycharm.tex

+21-17
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
\floatRowSep%
1515
%
1616
\subfloat[][%
17-
We click on the button for copying the URL to the clipboard.%
17+
We click on the button for copying the \pgls{URL} to the clipboard.%
1818
\label{fig:gitClonePycharm02copyUrl}%
1919
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/gitClonePycharm02copyUrl}}}%
2020
%
2121
\floatSep%
2222
%
2323
\subfloat[][%
24-
Now the URL is copied to the clipboard and we can paste it wherever we like via~\keys{\ctrl+V}.%
24+
Now the \pgls{URL} is copied to the clipboard and we can paste it wherever we like via~\keys{\ctrl+V}.%
2525
\label{fig:gitClonePycharm03copiedUrl}%
2626
]{\tightbox{\includegraphics[width=0.48\linewidth]{\currentDir/gitClonePycharm03copiedUrl}}}%
2727
%
@@ -55,8 +55,8 @@
5555
\floatSep%
5656
%
5757
\subfloat[][%
58-
Normally, we would write the URL of the repository that we want to clone into the \menu{URL:} field. %
59-
Here, we paste the repository URL that we copied from the \github\ page with \keys{\ctrl + V}. %
58+
Normally, we would write the \pgls{URL} of the repository that we want to clone into the \menu{URL:} field. %
59+
Here, we paste the repository \pgls{URL} that we copied from the \github\ page with \keys{\ctrl + V}. %
6060
We also enter a directory where the repository should be copied to into the \menu{Directory:} field. %
6161
Here, I simply selected a folder on my \linux\ temporary files partition (because I will delete the project once I am done with this example). %
6262
You would instead choose a more appropriate location. %
@@ -263,34 +263,38 @@
263263

264264
As usual, we work through a topic based on an example.
265265
This time, our goal is to \emph{download and get to run code from a \github\ repository in \pycharm.}
266-
As example repository, we pick the companion code of our \citetitle{databases} book~\cite{databases} at \url{\databasesCodeRepo}.
266+
Matter of fact, we already exercised the whole process of cloning the \github\ repository in \pycharm\ with the examples of this book in \cref{sec:gettingExamples}.
267+
To complement the excursion from back then, we this time pick the companion code of our \citetitle{databases} book~\cite{databases} at \url{\databasesCodeRepo} as example.
268+
This repository comes with a file \textil{requirements.txt}, which allows us to present the workflow of cloning a \git\ repository with setting up a \pgls{virtualEnvironment} and installing required packages into one single example.
267269

268-
In \cref{fig:gitClonePycharm01website}, we pretend that you came across this interesting repository on \github\ using your normal web browser
270+
Therefore, in \cref{fig:gitClonePycharm01website}, we pretend that you came across this interesting repository on \github\ using your normal web browser.
269271
If you visit \url{\databasesCodeRepo}, you can see the big drop down menu~\menu{Code}.
270-
If you click on it, it shows the HTTPS URL under which the project can be found in \cref{fig:gitClonePycharm02copyUrl}.
271-
If you work with \github, there are two ways to write a URL to a repository:%
272+
If you click on it, it shows the \pgls{HTTPS} \pgls{URL} under which the project can be found in \cref{fig:gitClonePycharm02copyUrl}.
273+
If you work with \github, there are two ways to write a \pgls{URL} to a repository:%
272274
%
273275
\begin{itemize}%
274276
%
275-
\item \url{https://github.com/user/repository} (or \url{https://github.com/user/repository.git}) use the HTTPS protocol to access the repository \textil{repository} of user \textil{user}. %
277+
\item \url{https://github.com/user/repository} (or \url{https://github.com/user/repository.git}) use \pgls{HTTPS} protocol to access the repository \textil{repository} of user \textil{user}. %
276278
This form is often and commonly used.%
277279
%
278-
\item \url{ssh://[email protected]/user/repository} (or \url{ssh://[email protected]/user/repository.git}) use SSH protocol to access the repository \textil{repository} of user \textil{user}. %
280+
\item \url{ssh://[email protected]/user/repository} (or \url{ssh://[email protected]/user/repository.git}) use \pgls{SSH} to access the repository \textil{repository} of user \textil{user}. %
279281
I find this form more reliable when working with \github\ from China.%
280282
%
281283
\end{itemize}%
282284
%
283285
Here, obviously, \textil{user} is \textil{thomasWeise}, which is my personal \github\ account, and \textil{repository} is \textil{databasesCode}.
284-
The URL that will be copied to the clipboard by clicking the button in \cref{fig:gitClonePycharm02copyUrl} is \url{https://github.com/thomasWeise/databasesCode.git}.
286+
The \pgls{URL} that will be copied to the clipboard by clicking the button in \cref{fig:gitClonePycharm02copyUrl} is \url{\databasesCodeRepo.git}.
287+
If you wanted to clone the repository with the example codes for this book instead, you would use \url{\programmingWithPythonCodeRepo.git}.
288+
285289
It is important to understand, however, that creating projects by cloning \git\ repositories is by no means restricted to \github.
286290
As stated before, \git\ is a \pgls{client}-\pgls{server} application.
287291
You could work in an enterprise that runs its own \git\ \pgls{server}.
288292
You could work with other \git-based repository hosts like \pgls{gitee}.
289-
Regardless of what \git\ service you use, you could use the very same way to type in the corresponding repository URL and then clone the repository in the same way.
290-
Only the structure of the URLs may be different.
293+
Regardless of what \git\ service you use, you could use the very same way to type in the corresponding repository \pgls{URL} and then clone the repository in the same way.
294+
Only the structure of the \pglspl{URL} may be different.
291295

292-
In \cref{fig:gitClonePycharm02copyUrl}, we click on the button for copying the URL to the clipboard.
293-
Now the URL is copied to the clipboard (\cref{fig:gitClonePycharm03copiedUrl}) and we can paste it wherever we like via~\keys{\ctrl+V}.
296+
In \cref{fig:gitClonePycharm02copyUrl}, we click on the button for copying the \pgls{URL} to the clipboard.
297+
Now the \pgls{URL} is copied to the clipboard (\cref{fig:gitClonePycharm03copiedUrl}) and we can paste it wherever we like via~\keys{\ctrl+V}.
294298
But where shall we paste it?
295299

296300
We open \pycharm.
@@ -301,8 +305,8 @@
301305
In that case, we click through \menu{\pycharmMainMenu > File > Project from Version Control\dots}.
302306

303307
Either way, the \inQuotes{Clone Repository} form appears in \cref{fig:gitClonePycharm05cloneRepositoryForm}.
304-
Normally, we would now write the URL of the repository that we want to clone into the \menu{URL:} field.
305-
Here, we paste the repository URL that we copied from the \github\ page with \keys{\ctrl + V}.
308+
Normally, we would now write the \pgls{URL} of the repository that we want to clone into the \menu{URL:} field.
309+
Here, we paste the repository \pgls{URL} that we copied from the \github\ page with \keys{\ctrl + V}.
306310
We also enter a directory where the repository should be copied to into the \menu{Directory:} field.
307311
This directory is where all the files will be downloaded to.
308312
You would normally select some appropriate place in your filesystem where you store your program codes.

0 commit comments

Comments
 (0)