Remote repositories
This commit is contained in:
parent
f0a89a4299
commit
f984737c9c
@ -448,10 +448,77 @@ What has happened is that Git has created an invisible directory (\texttt{.git})
|
|||||||
|
|
||||||
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 (\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 *}).
|
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 (\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 *}).
|
||||||
|
|
||||||
|
What about \texttt{git add -a}?
|
||||||
|
|
||||||
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 really 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 really doesn't penalize you either way. Personally, I prefer to make many smaller commits to avoid losing data.
|
||||||
|
|
||||||
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.}
|
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.}
|
||||||
|
|
||||||
|
\section{Branches}
|
||||||
|
|
||||||
|
If you want to experiment, the best way to do that is to create a \textit{branch}.
|
||||||
|
|
||||||
|
\section{Remote Repositories}
|
||||||
|
|
||||||
|
Remote repositories make it each to share your work and to collaborate with others. You can do all sorts of things locally, but at some point, you're probably going to want to put your work out there.
|
||||||
|
|
||||||
|
\subsection{Getting a Remote Repository}
|
||||||
|
|
||||||
|
If you set up a remote repo on some place like GitHub, or you find a repo somewhere that you would like to work with on your own, you can \textit{clone} that remote repo like this:
|
||||||
|
|
||||||
|
\input{include/clone}
|
||||||
|
|
||||||
|
For example, if you wanted to get a copy of the Apollo 11 Guidance Computer source code because you happen to be planning a trip to the moon of your own,\footnote{I was delighted to find out that this was available on GitHub. I first learned about this in the Volume Thirty-Eight, Number Four issue of \textit{2600} in an article called ``Supply and Demand, Apollo 11, and GitHub'', which is something I will probably talk about in the future.} you would just type \texttt{git clone https://github.com/chrisl\\garry/Apollo-11}. Git would create a directory called ``Apollo-11'' and clone a local version of that entire repository into it.
|
||||||
|
|
||||||
|
If you want to see the remotes attached to this repo, you can just type \texttt{git remote -v}. In this case, it would show you something like this:
|
||||||
|
|
||||||
|
\begin{Verbatim}[]
|
||||||
|
origin https://github.com/chrislgarry/Apollo-11 (fetch)
|
||||||
|
origin https://github.com/chrislgarry/Apollo-11 (push)
|
||||||
|
\end{Verbatim}
|
||||||
|
|
||||||
|
Of course, those remote repositories don't belong to you, so you can't push any changes you make to them. What you can do is create your own remote repo on a Git-hosting system. I'll do that on my Git site at \kref{https://git.kjodle.net/kjodle/Apollo-11}{https://git.kjodle.net/kjodle/Apollo-11}. To add that remote to my local repo, I will use this:
|
||||||
|
|
||||||
|
\input{include/remoteadd}
|
||||||
|
|
||||||
|
And running the \texttt{git remote -v} command again shows that I have two different remotes:
|
||||||
|
|
||||||
|
\begin{Verbatim}[]
|
||||||
|
ogit https://git.kjodle.net/kjodle/Apollo-11 (fetch)
|
||||||
|
ogit https://git.kjodle.net/kjodle/Apollo-11 (push)
|
||||||
|
origin https://github.com/chrislgarry/Apollo-11 (fetch)
|
||||||
|
origin https://github.com/chrislgarry/Apollo-11 (push)
|
||||||
|
\end{Verbatim}
|
||||||
|
|
||||||
|
I named my remote origin ``ogit'', which is the first letter of my last name combined with ``git''. Let's get rid of those remotes on GitHub, since I can't push any changes to them anyway. to do that we'll use this command:
|
||||||
|
|
||||||
|
\input{include/remoteremove}
|
||||||
|
|
||||||
|
Running \texttt{git remote -v} again shows that I now just have the remote on my own website:
|
||||||
|
|
||||||
|
\begin{Verbatim}[]
|
||||||
|
ogit https://git.kjodle.net/kjodle/Apollo-11 (fetch)
|
||||||
|
ogit https://git.kjodle.net/kjodle/Apollo-11 (push)
|
||||||
|
\end{Verbatim}
|
||||||
|
|
||||||
|
Are we ready to upload this code from my local repository to my remote repo? Not yet. Let's see what our local branches are by running \texttt{git branch}, which gives us this:
|
||||||
|
|
||||||
|
\begin{Verbatim}[]
|
||||||
|
* master
|
||||||
|
\end{Verbatim}
|
||||||
|
|
||||||
|
In this case, I only have a single branch, which is named ``master''. It also has an asterisk because it's the current branch. The problem here is that my Git website always names branches ``main''. So we need to change that branch name by running
|
||||||
|
|
||||||
|
\input{include/branchrename}
|
||||||
|
|
||||||
|
Running \texttt{git branch} again confirms that our branch has been renamed:
|
||||||
|
|
||||||
|
\begin{Verbatim}[]
|
||||||
|
* main
|
||||||
|
\end{Verbatim}
|
||||||
|
|
||||||
|
\subsection{Pushing Changes to a Remote Repository}
|
||||||
|
|
||||||
\section{Summary of Git Commands}
|
\section{Summary of Git Commands}
|
||||||
|
|
||||||
\begin{longtblr}
|
\begin{longtblr}
|
||||||
@ -467,18 +534,18 @@ If we're happy with the files we've staged, we can now commit them by using \tex
|
|||||||
rows = {5mm, m, rowsep=1.5pt},
|
rows = {5mm, m, rowsep=1.5pt},
|
||||||
row{1} = {font=\bfseries},
|
row{1} = {font=\bfseries},
|
||||||
rowhead = 1,
|
rowhead = 1,
|
||||||
cells = {font=\sffamily\fontsize{9pt}{12pt}\selectfont},
|
cells = {font=\sffamily\fontsize{8pt}{11pt}\selectfont},
|
||||||
}
|
}
|
||||||
Command & Purpose (\& Example) \\
|
Command & Purpose {\& Example, if applicable} \\
|
||||||
\texttt{init} & {Creates a git repository \\ \texttt{git init} } \\
|
\texttt{git init} & {Creates a local git repository \\ \texttt{git init} } \\
|
||||||
\texttt{clone} & {Clones a remote repository locally \\ \texttt{git clone} <URL of remote reposistory> } \\
|
\texttt{git clone} & {Clones a remote repository locally \\ \texttt{git clone} <URL of remote reposistory> } \\
|
||||||
\texttt{git --version} & Displays the version of git installed on your system \\
|
\texttt{git -{}-version} & Displays the version of git installed on your system \\
|
||||||
\texttt{add} & {Stages (i.e., adds) files to a commit \\ \texttt{git add file1 file2} } \\
|
\texttt{git add} & {Stages (i.e., adds) files to a commit \\ \texttt{git add file1 file2} } \\
|
||||||
\texttt{commit} & {Commits stages files \\ \texttt{git commit -m} ``<commit message>'' } \\
|
\texttt{git commit} & {Commits stages files \\ \texttt{git commit -m} ``<commit message>'' } \\
|
||||||
\texttt{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 push} & {Pushes a commit from a local repo to a remote repo \\ \texttt{git push} <name of remote repo> <name of remote branch> } \\
|
||||||
\texttt{} & { \\ \texttt{} } \\
|
\texttt{git remote} & {Show only the names of remote repos \\ \texttt{git remote} } \\
|
||||||
\texttt{} & { \\ \texttt{} } \\
|
\texttt{git remote -v} & {Show the names and URLs of remote repos \\ \texttt{git remote -v} } \\
|
||||||
\texttt{} & { \\ \texttt{} } \\
|
\texttt{} & { -{}- \\ \texttt{} } \\
|
||||||
\texttt{} & { \\ \texttt{} } \\
|
\texttt{} & { \\ \texttt{} } \\
|
||||||
\texttt{} & { \\ \texttt{} } \\
|
\texttt{} & { \\ \texttt{} } \\
|
||||||
\texttt{} & { \\ \texttt{} } \\
|
\texttt{} & { \\ \texttt{} } \\
|
||||||
|
3
005/include/branchrename.tex
Normal file
3
005/include/branchrename.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ git branch -m master main
|
||||||
|
\end{Verbatim}
|
3
005/include/clone.tex
Normal file
3
005/include/clone.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ git clone <URL of remote repo>
|
||||||
|
\end{Verbatim}
|
3
005/include/remoteadd.tex
Normal file
3
005/include/remoteadd.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ git remote add ogit https://git.kjodle.net/kjodle/Apollo-11
|
||||||
|
\end{Verbatim}
|
3
005/include/remoteremove.tex
Normal file
3
005/include/remoteremove.tex
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
\begin{Verbatim}[]
|
||||||
|
$ git remote remove origin
|
||||||
|
\end{Verbatim}
|
Loading…
Reference in New Issue
Block a user