我参考的文章,写的很详细:
https://www.cnblogs.com/YingYue/p/6058333.html?utm_source=itdadao&utm_medium=referral
1、服务器安装git 依赖:
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
安装git 执行命令: yum install -y git (-y表示安装过程中不需要手动确认,可以不加那么安装过程中需要输入y手动回车确认)
2、创建”用户组“和”用户“,用来运行git服务。
创建用户组: groupadd java_team
创建用户并whl添加到名为”java_team“的组中: adduser whl -g java_team
为用户名为whl的用户设置密码: passwd whl
3、安装Git客户端(开发人员安装)
下载地址https://git-scm.com/downloads 目前最新版本为:Git-2.10.2-64-bit.exe
生成公钥。安装后鼠标右键,如下:help->Show SSH Key
4:创建证书登录:
在用户 whl 的.ssh目录下创建authorized_keys文件
whl 的.ssh目录下创建authorized_keys文件
[root@localhost zhoujianxu]# cd /home/whl/
[root@localhost whl]# mkdir .ssh
[root@localhost whl]# ls -la
[root@localhost whl]# chmod 740 .ssh
[root@localhost whl]# touch .ssh/authorized_keys
[root@localhost whl]# chmod 600 .ssh/authorized_keys
[root@localhost whl]# chmod 740 .ssh
[root@localhost whl]# touch .ssh/authorized_keys
[root@localhost whl]# chmod 600 .ssh/authorized_keys
将id_rsa.pub 公钥添加到authorized_keys文件中:
cat id_rsa.pub >> .ssh/authorized_keys
5:服务器上初始化Git仓库,并把权限改为自己可读写执行,组不能写,其他没有权限
[root@localhost home]# mkdir git_repository
[root@localhost home]# chown -R whl:java_team git_repository
[root@localhost home]# cd git_repository/
[root@localhost git_repository]# git init --bare cms.git
[root@localhost git_repository]# chmod 750 -R cms.git
[root@localhost git_repository]# cd ..
[root@localhost git_repository]# chmod 750 -R git_repository
修改文件的所属组(权限向下递归更改为所属用户为whl所属组为java_team。):chown -R whl:java_team cms.git
6:使用本地Git Bash克隆服务器上的空仓库
git 先切换到你想存项目的位置。
我是存到e盘: cd /e/java //确保java下面没有cms.git文件夹
格式git clone user@ example.com:/*/*.git/
我的是:git clone root@192.*.*.*:/home/git_repository/xskk
就成功了。
7:将本地库推送到服务器
方法一
- 将eclipse中的cms项目复制到cms目录里(在你刚刚git的位置,我的就在e/java盘里)
- git add .把整个cms项目内文件的信息添加到索引库中,
- 使用git commit命令提交。(git将依据索引库中的内容来进行文件的提交) //git commit -m "项目初始版本"
- 执行git push -u origin master命令将本地cms_repository库的文件提交到远程服务器
方法二(如果本地仓库不是远端克隆来的,是自己创建的,那本地仓库不可能知道远端仓库在哪里,所以需要添加远程仓库)
- 方法一的前三步(提交到本地仓库)
- 添加远程仓库:git remote add origin whl@192.*.*.*:/home/git_repository/xskk
- 如果远程仓库不为空需要执行:git pull –rebase origin master
- 执行git push -u origin master命令将本地cms_repository库的文件提交到远程服务器
搞定啦。你的项目已经同步到服务器了。
8:导入本地Git库的项目到eclipse
Import -> git -> Project from Git -> Exising local repository -> add -> browse -> finish -> import existing eclipse project- finish.搞定啦。图片过程参考最上面的链接。
git指定ssh:
https://www.jianshu.com/p/ea50640ff704