ubuntu下构建自己的git仓库

环境:ubuntu16.04 + win10

备注:ubuntu下已经安装好ssh及git,win10下安装好git

参考文献:https://juejin.im/post/5a2696fcf265da43305e5423

​ https://blog.csdn.net/bbcckkl/article/details/81634761

错误参考:https://blog.csdn.net/leichelle/article/details/27378195

1. 服务器端

1.1 建立仓库

使用远程桌面登录自己的ubuntu服务器,进入git仓库文件夹,我的文件夹目录如下:

// 进入文件夹
cd /home/git
//建立仓库文件及初始化
git init --bare TestGit.git 

1.2 设置文件夹权限

错误主要有两个:

  1. push出现:
Yan@DESKTOP-3POIRM7 MINGW64 ~/GitTest/git/test (master)
$ git push origin master
[email protected]'s password:
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
fatal: sha1 file '' write error: Broken pipe
error: remote unpack failed: unpack-objects abnormal exit
error: failed to push some refs to '[email protected]:/home/git/TestGit/test.git'

原因:创建的git账户没有写文件的权限

解决办法:给git用户创建文件夹权限,

进行以下操作:

(1)进入root账户:sudo su

(2)赋予git用户权限:chown -R xxxx: .git

其中,XXX是用户名称。

  1. push出现
Yan@DESKTOP-3POIRM7 MINGW64 ~/GitTest/git/test (master)
$ git push origin master
[email protected]'s password:
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
fatal: sha1 file '' write error: Broken pipe
error: remote unpack failed: unpack-objects abnormal exit
error: failed to push some refs to '[email protected]:/home/git/TestGit/test.git'

原因:这是由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码:

解决办法:修改文件默认操作

执行以下代码:

git config receive.denyCurrentBranch ignore

2. 客户端

2.1 拉仓库数据

// git clone XXX@IP:/dir/name.git  XXX:用户名,IP:服务器IP, dir:仓库目录,name.git:仓库名称
$ git clone [email protected]:/home/git/LearnProject.git

2.2 修改仓库数据

向仓库中添加一些文件

2.3 同步本地数据到仓库

跟github上面的操作相同,执行git add ., git commit -m “”,git push origin master.

你可能感兴趣的:(系统)