1. git 仓库clone
#仓库clone
git clone git@github.com:15902124763/go-learning.git
2. 查看当前分支
#高亮显示的是当前分支,Linux 是分支前带*
git branch
3. 从本地master切分支
#feature_demo_20191226是切出的新的分支名称
git branch feature_demo_20191226
4. 从远程仓库切分支(如远程master分支)
#切出来的新分支名称:feature_demo2_20191226 ;origin:远程,master:远程分支名
git checkout -b feature_demo2_20191226 origin/master
5.提交本地
git commit -m "git commit demo"
6.合并分支到本地master并且提交到远程仓库
第一步、切分支到master
git checkout master
第二步、查看分支确认一下是否是master
git branch
第三步、拉取远程最新master代码
git pull
第四步、合并分支到本地master
git merge feature_demo2_20191226
第五步、没有冲突之后推到远程master分支
git push
7. Linux (centos)下载git
yum -y install git
8. git实现ssh
第一步、设置用户名email
#用户名
git config --global user.name "yarm"
#邮箱
git config --global user.email "xxxxx@163.com"
第二步、生成ssh key,一直回车
ssh-keygen -t rsa -C "xxxxxx@163.com"
第三步、拷贝.pub内容到git仓库
进入目录(前三步骤root用户)
#root用户注意
cd /root/.ssh
拷贝id_rsa.pub内容到远程仓库
以https://github.com/为例子,gitlab差不多
拷贝内容
内容
9. 新分支推送到远程仓库(首次push)
#首次 dev是远程分支名
git push origin dev
#分首次
git push
10. 查看远程所有分支
git branch -r
#origin/HEAD表示默认分支
origin/HEAD -> origin/master
11. 删除本地分支
git branch -d [you branch]
12. 删除远程分支
git push origin --delete [you origin branch]
13. 新分支首次推送远程仓库
git push --set-upstream origin [you will set origin branch]
14. 拉取远程仓库所有分支
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
15.git文件.gitignore部分文件不生效解决办法
git rm -r --cached .
git add .
git commit -m "fix .gitignore"
参考:https://www.jianshu.com/p/dc1a6f190be6
16.git 打tag
git tag release_1.0.0
推送
git push origin master --tags
https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE
参考资料:
https://git-scm.com/book/en/v2
17.git 本地的commit回退,代码不会消失
git reset --soft HEAD~2
HEAD~2表示回退两个版本