Environment is CentOS 7.4 64 bit
0. Preparation
- install git
yum install git
1. Developer - Generate personal SSH public key
Section 4.3 in the ps book is [Generate personal SSH public key], but the website version is [Git on the server - Generate SSH public key], because it is the user's public key, so the name in the book is more appropriate
Test on local win10, download and install Git for windows if Git is not installed
Open git Bash, ssh-keygen
press Enter a few times to generate (default in /c/Users/username/.ssh/id_rsa)
(*nix users use ssh-keygen directly)
Send id_rsa.pub
or id_dsa.pub
send it to the administrator, and it needs to be placed on the server.
2. Server - Git on the server, setting up the server
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
*.pub
Append the contents of the developer file ~/.ssh/authorized_keys
to .
/opt/git
Create a bare repository under
Export an existing repository as a new bare repository
git clone --bare https://github.com/onionc/Laravel-Messages.git messages.git
or
git init --bare
initialize a directorycd /opt/git mkdir messages.git cd messages.git git init --bare
Take a look at the directory. If you use the existing warehouse, there are a few more lines in the configuration file, and there are remote branch urls.
[root@x messages.git]# ll
total 36
drwxr-xr-x 2 root root 4096 Apr 22 15:26 branches
-rw-r--r-- 1 root root 138 Apr 22 15:26 config
-rw-r--r-- 1 root root 73 Apr 22 15:26 description
-rw-r--r-- 1 root root 23 Apr 22 15:27 HEAD
drwxr-xr-x 2 root root 4096 Apr 22 15:26 hooks
drwxr-xr-x 2 root root 4096 Apr 22 15:36 info
drwxr-xr-x 4 root root 4096 Apr 22 15:26 objects
-rw-r--r-- 1 root root 98 Apr 22 15:27 packed-refs
drwxr-xr-x 4 root root 4096 Apr 22 15:26 refs
[root@x my_project.git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
url = https://github.com/onionc/Laravel-Messages.git
This creates a new directory (minus the working directory).
3. Push your own code up
Since I already have a github remote repository locally, I git remote add
add a remote repository. Refer to 2.5 Git Basics - Using Remote Repositories
Build a remote warehouse (make sure the opt/git directory permission is git)
git remote add tx-origin [email protected]:/opt/git/messages.git
push data
git push tx-origin master
4. Cloning
Clone to another directory
$ git clone [email protected]:/opt/git/messages.git
Cloning into 'messages'...
[email protected]'s password:
remote: Counting objects: 200, done.
remote: Compressing objects: 100% (155/155), done.
remote: Total 200 (delta 25), reused 196 (delta 24)
Receiving objects: 100% (200/200), 1.17 MiB | 122.00 KiB/s, done.
Resolving deltas: 100% (25/25), done.
success. Try to modify a file and submit successfully
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
$ git add README.md
$ git commit -m '2'
[master 10c25ba] 2
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push
[email protected]'s password:
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 266 bytes | 266.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To 111.111.111.111:/opt/git/messages.git
2fa76cf..10c25ba master -> master
The privacy of the ps server ip 111.111.111.111 is all fabricated.
0. Question: Where are the files stored?
No project file was found in the messages.git directory of the server
[git@x messages.git]$ ll
total 32
drwxrwxr-x 2 git git 4096 Apr 22 20:57 branches
-rw-rw-r-- 1 git git 66 Apr 22 20:57 config
-rw-rw-r-- 1 git git 73 Apr 22 20:57 description
-rw-rw-r-- 1 git git 23 Apr 22 20:57 HEAD
drwxrwxr-x 2 git git 4096 Apr 22 20:57 hooks
drwxrwxr-x 2 git git 4096 Apr 22 20:57 info
drwxrwxr-x 7 git git 4096 Apr 22 21:28 objects
drwxrwxr-x 4 git git 4096 Apr 22 20:57 refs
So where are the project files stored after they are pushed?
Found a similar question: Build a git server by yourself, why can't the local file be pushed to the server? The answer is: The directory project001.git on the git server is just a warehouse. You need to find a directory to clone it, and it will show you push the content above .
But where is it stored? ( Why are pigeons so big?
All server-side work is done by the update(update.sample) script file in the hooks directory - proficient in Git Second Edition, 8.4.1
I found one in my English:
Git Push worked, but files are not on server
The answer said
The files are there, you just don't see them because they are embedded into the Git database. This is the difference between initializing a repository with --bare or without
The files are there, you just can't see them because they're embedded in the Git database. This is the difference between initializing a bare repository.
In this way, I will not delve into it in the database. I can't understand 80% of my dishes. I will study it later.
The answer left a reference What is a bare git repository?
Find a few important sentences:
Repositories created with
git init --bare
are called bare repos. They are structured a bit differently from working directories. First off, they contain no working or checked out copy of your source files. And second, bare repos store git revision history of your repo in the root folder of your repository instead of in a .git subfolder.
A bare repository created with git init --bare is for… sharing.
Because git is a distributed version control system, no one will directly edit files in the shared centralized repository.
Because no one ever makes edits directly to files in the shared bare repo, a working tree is not needed. In fact the working tree would just get in way and cause conflicts as users push code to the repository. This is why bare repositories exist and have no working tree.
git init --bare
Repositories created using this are called bare repos. Their structure is slightly different from the working directory. First, they do not contain any work or check copies of the source files. .git
Second, only use repos to store your repo's history in the root folder of the repository, not in a subfolder.
Use git init --bare
a bare repository created for... sharing.
Because git is a distributed version control system, no one will edit files directly in a shared centralized repository.
Since no one is directly editing the shared bareback file, there is no need for a working tree. In fact, the working tree causes conflicts when users push code into the repository. That's why bare repositories exist and no working trees.