git远程服务搭建与简单实用
@Author Will.He
@email will-he@hotamil.com
#git server centos7 install document
step 0:
#在远端服务器安装git服务(CentOS7@ALIYUM)
yum install -y git
git –version (this cmd can verify your git install is successfully)
step1:
#生成本地的公钥私钥文件
sh-keygen -t rsa -C ‘your email address for loginname’
#for example:
ssh-keygen -t rsa -C 'yourEmail@qq.com‘
tip1: When you run the cmd above, I mean before the local pc or mac really generate your key pairs, the computer will ask you for a file name for the key file. I strongly recomend you to type your email string before @ as the file name,somehow you can easily recognize the key by its name and why it is made;
tip2:When your local computer ask you for the passphrase ,you may directly tpye enter.(it means no passphrase)
tip3:If your computer generate the key pairs,you can find the files in the directory which is your current specific path.
step2:
#这是服务器上的操作,不是本地电脑操作
#创建git用户,if you think other name is better ,it is your call;
adduser git
#创建密码
password git
#创建.ssh文件夹
su git
cd ~
mkdir .ssh
#修改sshd配置文件,让服务器支持公钥登陆
vi /etc/ssh/sshd_config
#取消下面两个配置的注释
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#重启sshd服务
systemctl restart sshd.service
step3
#将本地公钥导入到服务器,本地操作
ssh git@your server ip ‘cat >> .ssh/authorized_keys’ < ~/.ssh/785476800.pub
tip: you may be asked for a password to access the remote server. this password is the one which you make for user git in step2;
step4
#解决可能的文件权限问题,服务器上操作
su root
chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys
step 5:
It is done;
you can use the git cmd to operate your file ,and enjoy your git journey
if you don’t want user git login from ssh client for safety, and please at ease,it is no bussiness to git login
you may vi /etc/passed ,and find the git:x:10001:10001::/home/git:/bin/bash,and change the bash to git-shell and :wq
at last:
the cmd in common use
====================================在remote建立git仓库并拉取到本地==========================================
#how to generate a git repository in the remote Server
cd to your git directory ,/home/git/remote e.g.
if there is noting,make one;
#name a directory which your project want to name
/home/git/remote/hello-git e.g.
#then use the cmd below to init the git repository
mkdir hello-git.git (recomend you to name this directory similary like your project name)
#创建裸体仓库,只能查看版本
git init –bare hello-git.git
#解决可能的权限问题
chown -R git:git hello-git.git
#克隆远端仓库文件到本地
git clone git@ip:your git project directory path (which contain a xx.git file)
git clone git@ip.ip.ip.ip:/home/git/remote/r2/r2.git e.g.
#查看本地git管理文件的状态
git status
将文件提交到到unstage
git add
#将文件提交到stage
git commit -m “提交的说明文字”
file 写成 . 是目录下的管理文件全部提交
#将文件推送到远端服务器
git push -u origin master
origin:当前远程服务器 使用 git remote 可以获得
master:当前主分支
#从远程仓库拉取文件(这个建立在已经和远端git仓库建立关联的前提下)
git pull origin master
=========================================在本地老项目中提交到remote服务器=================================================
cd your local project directory
git init
git add .
git commit -m “your local project xxxx init “
#warning : please make sure your remote repository is clean !
git remote add origin git@ip.ip.ip.ip:/home/git/remote/r2/r2.git e.g.
verify the result of the cmd above
git remote -v
#提交本地文件到远端仓库
git push origin master
Done!
================================config the git’s .gitignore file===========================================
I save the .gitignore file to the onedrive/git_global_config
git config –global core.excludesfile ~/Document/oneDrive/git_global_config/.gitignore
the rules is in the file
common cmds those we usually use
1.查询当前git file tree的文件状态(结构)
git status
2.添加当前目录下的所有文件到git file tree
git add . (注意这里有个点哦)
3.提交改动
git commit -a -m ‘mark the reason why u modify these files’
4.推送到远程仓库
git push -u origin master
enter your remote git account pwd
5.拉取远程仓库的内容到当前目录
git pull origin master
your git pwd as well
以上未考虑版本分支的情况,也不曾搭建gitlab服务,只做了一点微小的工作,only wish to offer some help to the fellows who fork me





