文章目录
Linux创建git服务器
一、服务器安装Git
Linux 做为服务器端系统,Windows 作为客户端系统,分别安装 Git.
服务器端:
#yum install -y git
//安装成功查看版本
#git --version
git version 1.8.3.1
客户端:
https://git-scm.com/download/win
//下载对应版本
//安装成功以后查看版本
Window+R--->CMD//打开命令行
#git --version
二、服务器端创建git用户,用来管理Git服务,并为git用户设置密码
[root@localhost ~]# git --version
git version 1.8.3.1
[root@localhost ~]# id git
id: git: no such user
[root@localhost ~]# useradd git
[root@localhost ~]# passwd git
更改用户 git 的密码 。
新的 密码:
重新输入新的 密码:
三、服务器端创建 Git 仓库
-
设置 /home/data/git/gittest.git 为 Git 仓库
-
然后将Git仓库文件的属主改为git用户。
[root@localhost home]# mkdir -p data/git/gittest.git
[root@localhost home]# git init --bare data/git/gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost home]# cd data/git/
[root@localhost git]# chown -R git:git gittest.git/
chown命令详解使用格式和方法
利用 chown 可以将档案的拥有者加以改变。这个指令只有是由系统管理者(root)所使用,一般使用者没有权限可以改变别人的档案拥有者,也没有权限可以自己的档案拥有者改设为别人。只有系统管理者(root)才有这样的权限。
参数
-
-c或-change:作用与-v相似,但只传回修改的部分
-
-f或–quiet或–silent:不显示错误信息
-
-h或–no-dereference:只对符号链接的文件做修改,而不更改其他任何相关文件
-
-R或-recursive:递归处理,将指定目录下的所有文件及子目录一并处理
-
-v或–verbose:显示指令执行过程
-
–dereference:作用和-h刚好相反
-
–help:显示在线说明
-
–reference=<参考文件或目录>:把指定文件或目录的所有者与所属组,统统设置成和参考文件或目录的所有者与所属组相同
-
–version:显示版本信息
chown [-R] [用户名称] [文件或目录]
chown [-R] [用户名称:组名称] [文件或目录]
四、客户端clone远程仓库
创建项目地址 d:/workspace/test/pratise
cd d:/workspace/test/pratise
git git clone git@192.168.56.103:/home/data/git/gittest.git
还可以看后续—》》Linux搭建git服务器
五、本地创建git项目往git仓库上传
创建一个本地的git项目文件夹,名称任意!
我的地址是:D:\workspace\test\pratis
//命令行进入
#cd D:\workspace\test\pratis
//git初始化
#git init //然后在文件夹内部会创建一个.git文件夹
//创建一个README.TXT文件,我们将这个文件进行上传测试
#git status //查看状态
//No commits yet
//Untracked files:(use "git add <file>..." to include in what will be committed)
// README.txt
//nothing added to commit but untracked files present (use "git add" to track)
//经过查看状态我们会发现有一个README.TXT文件没有commit
#git add .\README.txt
#git status //查看状态
//No commits yet
//Changes to be committed:
//(use "git rm --cached <file>..." to unstage)
//new file: README.txt
git commit -m "the first commit" //文件上传到本地仓库,并注释“the first commit”
//*** Please tell me who you are.
//Run
//git config --global user.email "you@example.com"
//git config --global user.name "Your Name"
//to set your account's default identity.
//Omit --global to set the identity only in this repository.
//这个错误意思就是你们有设置邮箱和用户名,在git中需要通过这两个条件,来定位是谁上传的文件
git config --global user.email "tianya5693@163.com"
git config --global user.name "pratise"
git commit -m "the first commit" //再次提交
git log //查看日志
//commit ec32ffbb164d892ee4ac19c7f64d7666c95ee2ac (HEAD -> master)
//Author: pratise <tianya5693@163.com>
//Date: Wed Apr 25 21:52:42 2018 +0800
//the first commit
//然而现在我们只是提交到本地仓库,我们需要将我们的文件push到远程服务器上去
//这时候我们需要对我们本地的git文件添加远程仓库地址
git remote //查询仓库地址
//空 说明没有
git remote add origin git@192.168.56.103:/home/data/git/gittest.git
//添加一个叫origin的远程仓库
git remote //再次查询
// origin
git branch //查看分支
//* master 我们看到我们有一个master本地分支
git push -u origin master
// 这时我们就将我们的文件上传到了远程仓库中