官网下载地址:
https://github.com/git/git/releases/
Linux直接下载:
wget https://github.com/git/git/archive/v2.26.2.tar.gz
依赖安装:
yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
解压安装:
cd /usr/local/src
tar -zxvf tar -zxvf git-2.26.2.tar.gz
cd git-2.26.2/
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
git验证
git --version
克隆项目:
cd /usr/local/src
mkdir gitdownload
cd gitdownload
git clone git@gitee.com:jack_party/mmall.git
提示没有权限(需要设置SSH公钥):
git ssh key pair配置(一路回车,生成ssh key pair)
ssh-keygen -t rsa -C “854877150@qq.com”
ssh-add ~/.ssh/id_rsa(如果出现错误Could not open a connection to your authentication agent.,先执行 eval ssh-agent
再执行本条成功 ssh-add -l 就有新家的rsa
了)
cat ~/.ssh/id_rsa.pub(得到公钥):
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDaCPJpIvMBBEd0IDNKCXEHsP84Bxgk5lux15QFZswBiNhkDWX/w78s1yobisxS4dbfu7INg9Hpiy7X3oN/Blu8Ue0bthwIyg3xbmzHC
+PcSHvAI7TgBWpjzvet1tqqfILBpPB6uuFfY/UxZJOQdDCU7DSdL26bAptNdyiABC3H3WNGaHsP4ShRBAbzCMAJU0S4CBDS77wWUv9N9+xA7jDNi6ujU53YI53m7nKgHkMf/tLGgHV
+Q1Bl08tm7lWcxB9MqJk/NrME56nnPG97Gz1gW7DYJxUmzfhox0yDXmAT4WN+xvKVeRJX6VjkKOLhb3OoXWi5r2lU6CoveAnOpNAl 854877150@qq.com
把得到公钥放到github或者码云的项目公钥里。
再执行:git clone git@gitee.com:jack_party/mmall.git 克隆项目。
cd mmall
分支查看:git branch -r
分支切换:git checkout v1.0
查看当前分支:git branch
拉取:git pull
配置用户名
git config --global user.name ‘jack’
配置邮箱
git config --global user.email ‘854877150@qq.com’
其他配置:
让GIt不要管Windows/Unix 换行符转换的事
git config --global core.autocrlf false
编码配置
避免git gui中的中文乱码
git config --global gui.encoding utf-8
避免git status显示的中文文件名乱码
git config --global core.quotepath off
Windows上还需配置
git config --global core.ignorecase false
常用命令:
(1)切换分支:git checkout 分支名
(2)拉取:git pull
(3)提交:git push
git项目初始化:
touch .gitignore(项目根目录创建git忽略文件)
.gitignore文件内容:
*.class
#package file
*.war
*.ear
#maven ignore
target/
#eclipse ignore
.settings/
.project
.classpath
#idea ignore
.idea/
/idea/
*.ipr
*.iml
*.iws
#temp file ignore
*.log
*.cache
*.diff
*.patch
*.tmp
#system ignore
.DS_Store
Thumbs.db
初始化git项目:
git init
git status
git add .
git status
git commit -am ‘first commot init project’(提交到本地)
git remote add origin git@gitee.com:jack_party/mmall.git(连接远程)
git branch
git push -u origin master(报错,得先执行git pull)
git pull
git push -u origin master(分支比较落后)
git push -u -f origin master(强制)
git branch -r (分支)
git checkout -b v1.0 origin/master(检出,开分支,在master基础上分支出v1.0分支)
git branch (检查当前分支)
git push origin HEAD -u(提交分支)