You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/04-git-server/1-git-server.asc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
At this point, you should be able to do most of the day-to-day tasks for which you'll be using Git.
5
5
However, in order to do any collaboration in Git, you'll need to have a remote Git repository.
6
6
Although you can technically push changes to and pull changes from individuals' repositories, doing so is discouraged because you can fairly easily confuse what they're working on if you're not careful.
7
-
Furthermore, you want your collaborators to be able to access the repository even if your computer is offline – having a more reliable common repository is often useful.
7
+
Furthermore, you want your collaborators to be able to access the repository even if your computer is offline -- having a more reliable common repository is often useful.
8
8
Therefore, the preferred method for collaborating with someone is to set up an intermediate repository that you both have access to, and push to and pull from that.
9
9
10
10
Running a Git server is fairly straightforward.
@@ -15,7 +15,7 @@ Last, we'll go over a few hosted options, if you don't mind hosting your code on
15
15
16
16
If you have no interest in running your own server, you can skip to the last section of the chapter to see some options for setting up a hosted account and then move on to the next chapter, where we discuss the various ins and outs of working in a distributed source control environment.
17
17
18
-
A remote repository is generally a _bare repository_– a Git repository that has no working directory.
18
+
A remote repository is generally a _bare repository_-- a Git repository that has no working directory.
19
19
Because the repository is only used as a collaboration point, there is no reason to have a snapshot checked out on disk; it's just the Git data.
20
20
In the simplest terms, a bare repository is the contents of your project's `.git` directory and nothing else.
Copy file name to clipboardExpand all lines: book/04-git-server/sections/protocols.asc
+30-30Lines changed: 30 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
=== The Protocols
2
2
3
-
Git can use four major protocols to transfer data: Local, HTTP, Secure Shell (SSH) and Git.
3
+
Git can use four distinct protocols to transfer data: Local, HTTP, Secure Shell (SSH) and Git.
4
4
Here we'll discuss what they are and in what basic circumstances you would want (or not want) to use them.
5
5
6
6
==== Local Protocol
7
7
8
8
(((protocols, local)))
9
-
The most basic is the _Local protocol_, in which the remote repository is in another directory on disk.
9
+
The most basic is the _Local protocol_, in which the remote repository is in another directory on the same host.
10
10
This is often used if everyone on your team has access to a shared filesystem such as an NFS mount, or in the less likely case that everyone logs in to the same computer.
11
11
The latter wouldn't be ideal, because all your code repository instances would reside on the same computer, making a catastrophic loss much more likely.
Git operates slightly differently if you explicitly specify `file://` at the beginning of the URL.
30
30
If you just specify the path, Git tries to use hardlinks or directly copy the files it needs.
31
-
If you specify `file://`, Git fires up the processes that it normally uses to transfer data over a network which is generally a lot less efficient method of transferring the data.
32
-
The main reason to specify the `file://` prefix is if you want a clean copy of the repository with extraneous references or objects left out – generally after an import from another version-control system or something similar (see <<_git_internals>> for maintenance tasks).
31
+
If you specify `file://`, Git fires up the processes that it normally uses to transfer data over a network, which is generally much less efficient.
32
+
The main reason to specify the `file://` prefix is if you want a clean copy of the repository with extraneous references or objects left out -- generally after an import from another VCS or something similar (see <<_git_internals>> for maintenance tasks).
33
33
We'll use the normal path here because doing so is almost always faster.
34
34
35
35
To add a local repository to an existing Git project, you can run something like this:
@@ -39,7 +39,7 @@ To add a local repository to an existing Git project, you can run something like
39
39
$ git remote add local_proj /srv/git/project.git
40
40
----
41
41
42
-
Then, you can push to and pull from that remote as though you were doing so over a network.
42
+
Then, you can push to and pull from that remote via your new remote name `local_proj` as though you were doing so over a network.
43
43
44
44
===== The Pros
45
45
@@ -49,7 +49,7 @@ You stick the bare repository copy somewhere everyone has shared access to and s
49
49
We'll discuss how to export a bare repository copy for this purpose in <<_git_on_the_server>>.
50
50
51
51
This is also a nice option for quickly grabbing work from someone else's working repository.
52
-
If you and a co-worker are working on the same project and they want you to check something out, running a command like `git pull /home/john/project` is often easier than them pushing to a remote server and you pulling down.
52
+
If you and a co-worker are working on the same project and they want you to check something out, running a command like `git pull /home/john/project` is often easier than them pushing to a remote server and you subsequently fetching from it.
53
53
54
54
===== The Cons
55
55
@@ -61,21 +61,21 @@ A local repository is fast only if you have fast access to the data.
61
61
A repository on NFS is often slower than the repository over SSH on the same server, allowing Git to run off local disks on each system.
62
62
63
63
Finally, this protocol does not protect the repository against accidental damage.
64
-
Every user has full shell access to the "remote" directory, and there is nothing preventing them from changing or removing internal Git files and corrupting the repository.
64
+
Every user has full shell access to the ``remote'' directory, and there is nothing preventing them from changing or removing internal Git files and corrupting the repository.
65
65
66
66
==== The HTTP Protocols
67
67
68
-
Git can communicate over HTTP in two different modes.
69
-
Prior to Git 1.6.6 there was only one way it could do this which was very simple and generally read-only.
70
-
In version 1.6.6 a new, smarter protocol was introduced that involved Git being able to intelligently negotiate data transfer in a manner similar to how it does over SSH.
68
+
Git can communicate over HTTP using two different modes.
69
+
Prior to Git 1.6.6, there was only one way it could do this which was very simple and generally read-only.
70
+
In version 1.6.6, a new, smarter protocol was introduced that involved Git being able to intelligently negotiate data transfer in a manner similar to how it does over SSH.
71
71
In the last few years, this new HTTP protocol has become very popular since it's simpler for the user and smarter about how it communicates.
72
-
The newer version is often referred to as the ``Smart'' HTTP protocol and the older way as ``Dumb'' HTTP.
73
-
We'll cover the newer ``smart'' HTTP protocol first.
72
+
The newer version is often referred to as the _Smart_ HTTP protocol and the older way as _Dumb_ HTTP.
73
+
We'll cover the newer Smart HTTP protocol first.
74
74
75
75
===== Smart HTTP
76
76
77
77
(((protocols, smart HTTP)))
78
-
The ``smart'' HTTP protocol operates very similarly to the SSH or Git protocols but runs over standard HTTP/S ports and can use various HTTP authentication mechanisms, meaning it's often easier on the user than something like SSH, since you can use things like username/password authentication rather than having to set up SSH keys.
78
+
Smart HTTP operates very similarly to the SSH or Git protocols but runs over standard HTTPS ports and can use various HTTP authentication mechanisms, meaning it's often easier on the user than something like SSH, since you can use things like username/password authentication rather than having to set up SSH keys.
79
79
80
80
It has probably become the most popular way to use Git now, since it can be set up to both serve anonymously like the `git://` protocol, and can also be pushed over with authentication and encryption like the SSH protocol.
81
81
Instead of having to set up different URLs for these things, you can now use a single URL for both.
@@ -87,9 +87,9 @@ In fact, for services like GitHub, the URL you use to view the repository online
87
87
===== Dumb HTTP
88
88
89
89
(((protocols, dumb HTTP)))
90
-
If the server does not respond with a Git HTTP smart service, the Git client will try to fall back to the simpler ``dumb'' HTTP protocol.
90
+
If the server does not respond with a Git HTTP smart service, the Git client will try to fall back to the simpler _Dumb_ HTTP protocol.
91
91
The Dumb protocol expects the bare Git repository to be served like normal files from the web server.
92
-
The beauty of the Dumb HTTP protocol is the simplicity of setting it up.
92
+
The beauty of Dumb HTTP is the simplicity of setting it up.
93
93
Basically, all you have to do is put a bare Git repository under your HTTP document root and set up a specific `post-update` hook, and you're done (See <<_git_hooks>>).
94
94
At that point, anyone who can access the web server under which you put the repository can also clone your repository.
95
95
To allow read access to your repository over HTTP, do something like this:
@@ -112,8 +112,8 @@ This command is run when you push to this repository (over SSH perhaps); then, o
112
112
$ git clone https://example.com/gitproject.git
113
113
----
114
114
115
-
In this particular case, we're using the `/var/www/htdocs` path that is common for Apache setups, but you can use any static web server – just put the bare repository in its path.
116
-
The Git data is served as basic static files (see <<_git_internals>> for details about exactly how it's served).
115
+
In this particular case, we're using the `/var/www/htdocs` path that is common for Apache setups, but you can use any static web server -- just put the bare repository in its path.
116
+
The Git data is served as basic static files (see the <<_git_internals>> chapter for details about exactly how it's served).
117
117
118
118
Generally you would either choose to run a read/write Smart HTTP server or simply have the files accessible as read-only in the Dumb manner.
119
119
It's rare to run a mix of the two services.
@@ -129,22 +129,22 @@ It is also a very fast and efficient protocol, similar to the SSH one.
129
129
130
130
You can also serve your repositories read-only over HTTPS, which means you can encrypt the content transfer; or you can go so far as to make the clients use specific signed SSL certificates.
131
131
132
-
Another nice thing is that HTTP/S are such commonly used protocols that corporate firewalls are often set up to allow traffic through these ports.
132
+
Another nice thing is that HTTPS are such commonly used protocols that corporate firewalls are often set up to allow traffic through these ports.
133
133
134
134
===== The Cons
135
135
136
-
Git over HTTP/S can be a little more tricky to set up compared to SSH on some servers.
137
-
Other than that, there is very little advantage that other protocols have over the ``Smart'' HTTP protocol for serving Git.
136
+
Git over HTTPS can be a little more tricky to set up compared to SSH on some servers.
137
+
Other than that, there is very little advantage that other protocols have over Smart HTTP for serving Git content.
138
138
139
139
If you're using HTTP for authenticated pushing, providing your credentials is sometimes more complicated than using keys over SSH.
140
-
There are however several credential caching tools you can use, including Keychain access on macOS and Credential Manager on Windows, to make this pretty painless.
140
+
There are, however, several credential caching tools you can use, including Keychain access on macOS and Credential Manager on Windows, to make this pretty painless.
141
141
Read <<_credential_caching>> to see how to set up secure HTTP password caching on your system.
142
142
143
143
==== The SSH Protocol
144
144
145
145
(((protocols, SSH)))
146
146
A common transport protocol for Git when self-hosting is over SSH.
147
-
This is because SSH access to servers is already set up in most places – and if it isn't, it's easy to do.
147
+
This is because SSH access to servers is already set up in most places -- and if it isn't, it's easy to do.
148
148
SSH is also an authenticated network protocol and, because it's ubiquitous, it's generally easy to set up and use.
149
149
150
150
To clone a Git repository over SSH, you can specify an `ssh://` URL like this:
@@ -166,24 +166,24 @@ In both cases above, if you don't specify the optional username, Git assumes the
166
166
===== The Pros
167
167
168
168
The pros of using SSH are many.
169
-
First, SSH is relatively easy to set up – SSH daemons are commonplace, many network admins have experience with them, and many OS distributions are set up with them or have tools to manage them.
170
-
Next, access over SSH is secure – all data transfer is encrypted and authenticated.
171
-
Last, like the HTTP/S, Git and Local protocols, SSH is efficient, making the data as compact as possible before transferring it.
169
+
First, SSH is relatively easy to set up -- SSH daemons are commonplace, many network admins have experience with them, and many OS distributions are set up with them or have tools to manage them.
170
+
Next, access over SSH is secure -- all data transfer is encrypted and authenticated.
171
+
Last, like the HTTPS, Git and Local protocols, SSH is efficient, making the data as compact as possible before transferring it.
172
172
173
173
===== The Cons
174
174
175
-
The negative aspect of SSH is that you can't serve anonymous access of your repository over it.
176
-
People must have access to your machine over SSH to access it, even in a read-only capacity, which doesn't make SSH access conducive to open source projects.
175
+
The negative aspect of SSH is that it doesn't support anonymous access to your Git repository.
176
+
If you're using SSH, people _must_ have SSH access to your machine, even in a read-only capacity, which doesn't make SSH conducive to open source projects for which people might simply want to clone your repository to examine it.
177
177
If you're using it only within your corporate network, SSH may be the only protocol you need to deal with.
178
-
If you want to allow anonymous read-only access to your projects and also want to use SSH, you’ll have to set up SSH for you to push over but something else for others to fetch over.
178
+
If you want to allow anonymous read-only access to your projects and also want to use SSH, you’ll have to set up SSH for you to push over but something else for others to fetch from.
179
179
180
180
==== The Git Protocol
181
181
182
182
(((protocols, git)))
183
183
Next is the Git protocol.
184
184
This is a special daemon that comes packaged with Git; it listens on a dedicated port (9418) that provides a service similar to the SSH protocol, but with absolutely no authentication.
185
-
In order for a repository to be served over the Git protocol, you must create the `git-daemon-export-ok` file – the daemon won't serve a repository without that file in it – but other than that there is no security.
186
-
Either the Git repository is available for everyone to clone or it isn't.
185
+
In order for a repository to be served over the Git protocol, you must create a `git-daemon-export-ok` file -- the daemon won't serve a repository without that file in it -- but other than that there is no security.
186
+
Either the Git repository is available for everyone to clone, or it isn't.
187
187
This means that there is generally no pushing over this protocol.
188
188
You can enable push access but, given the lack of authentication, anyone on the internet who finds your project's URL could push to that project.
0 commit comments