mirror of
https://github.com/ZJDoc/GitGuide.git
synced 2026-07-29 15:20:25 +08:00
docs(git): add advanced and error
This commit is contained in:
60
docs/git/advanced/创建裸仓库.md
Normal file
60
docs/git/advanced/创建裸仓库.md
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
# 创建裸仓库
|
||||
|
||||
裸仓库,也就是不包含当前工作目录的仓库,即`.git`文件夹,可作为服务器`git`仓库
|
||||
|
||||
有两种方式,一是使用本地已存在的仓库,二是新建远程裸仓库
|
||||
|
||||
## 本地导出
|
||||
|
||||
从已有仓库中导出`.git`文件夹,有两种方式
|
||||
|
||||
1. 使用`git`命令
|
||||
|
||||
git clone --bare my_project my_project.git
|
||||
|
||||
$ git clone --bare TEST TEST.git
|
||||
Cloning into bare repository 'TEST.git'...
|
||||
done.
|
||||
|
||||
2. 使用`cp`命令
|
||||
|
||||
cp -rf my_project/.git my_project.git
|
||||
|
||||
### 放置在远程服务器
|
||||
|
||||
在服务器上新建文件夹`git`
|
||||
|
||||
$ pwd
|
||||
/home/ubuntu/git
|
||||
|
||||
复制本地裸仓库到服务器
|
||||
|
||||
$ scp -r TEST.git ubuntu@132.232.142.219:/home/ubuntu/git/TEST.git
|
||||
|
||||
这样在`git`文件夹下就有了裸仓库`TEST.git`
|
||||
|
||||
$ pwd
|
||||
/home/ubuntu/git/TEST.git
|
||||
|
||||
## 远程新建
|
||||
|
||||
在远程服务器新建文件夹,并在其中初始化为裸仓库
|
||||
|
||||
$ mkdir TE.git
|
||||
$ cd TE.git
|
||||
$ git init --bare
|
||||
Initialized empty Git repository in /home/ubuntu/git/TE.git/
|
||||
# 如果想要同一组内的其他用户也可访问该仓库,添加参数--shared来修改仓库权限
|
||||
$ git init --bare --shared
|
||||
Initialized empty shared Git repository in /home/ubuntu/git/TE.git/
|
||||
|
||||
## 克隆裸仓库
|
||||
|
||||
和`github`操作方式类似
|
||||
|
||||
git clone ubuntu@132.232.142.219:/home/ubuntu/git/TEST.git
|
||||
|
||||
## 相关阅读
|
||||
|
||||
* [4.2 服务器上的 Git - 在服务器上搭建 Git](https://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%9C%A8%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E6%90%AD%E5%BB%BA-Git)
|
||||
Reference in New Issue
Block a user