源码安装
访问地址:https://git-scm.com/download/linux
https://mirrors.edge.kernel.org/pub/software/scm/git/找到最新版本的tar.gz包
本次下载git-2.20.1.tar.gz安装git的依赖项
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost yum.repos.d]# yum -y install gcc perl-ExtUtils-MakeMaker
移除已安装的git
[root@localhost ~]# yum remove git
解压安装包
[root@localhost ~]# tar -zxvf git-2.20.1.tar.gz
进入解压目录,预编译git
[root@localhost ~]# cd git-2.20.1
[root@localhost git-2.20.1]# ./configure --prefix=/usr/local/git
编译并安装git
[root@localhost git-2.20.1]# make && make install
将git的脚本软连接到/usr/bin/目录下
[root@localhost git-2.20.1]# ln -s /usr/local/git/bin/* /usr/bin/
检测是否安装成功
[root@localhost git-2.20.1]# git --version
全局配置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
与某远程仓库关联
创建一个新仓库
git clone git@gitlab.whenling.com:root/blank-project.git
cd blank-project
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
在已存在的文件夹下
cd existing_folder
git init
git remote add origin git@gitlab.whenling.com:root/blank-project.git
git add .
git commit -m "Initial commit"
git push -u origin master
在已存在的仓库下
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.whenling.com:root/blank-project.git
git push -u origin --all
git push -u origin --tags
本地与远程仓库不一致时拉取
git pull origin master --allow-unrelated-histories