Git 快速入门
Git可以简单理解为3角阵关系:
![三角阵](https://i-blog.csdnimg.cn/blog_migrate/de0545321b47f376655a0dc6411c2a77.png)
1. 拿
看到某个心仪的项目,先克隆到本地
git clone git://xxx.xxx.git
2. 建
直接在master改不符合规范,先建个自己的分支,-b参数直接切到该分支
git checkout -b test/csdn
3. 推
在test/csdn分支加了代码,提交到本地仓库防止丢失
git add .
git commit -m "Add unit tests"
现在推上远程仓库
git push -u origin test/csdn
4. 删
第一种是:本地仓库的test/csdn需要删掉(此操作不影响远程仓库)
git branch -d test/csdn
第二种是:远程仓库的test/csdn不需要了(本地暂时不管)
git push origin --delete test/csdn
5. 合
我的新分支[new/csdn]经过测试没有问题,需要合入远程仓库的master跟大家共享
git checkout master
git pull
git rebase new/csdn
git push
》》常见问题集:
- 场景A:某个分支的名字不合理或有错别字,需要修改本地和远程(比如:text需要改为txt)
# 删除远程仓库的text分支
git push origin --delete text
# 修改本地分支名字为txt
git branch -m text txt
# 设置关联并推送txt到远程仓库
git push --set-upstream origin txt
- 场景B:本地的csdn分支和远程csdn分支有冲突,无法拉取,又无法切换到其他分支,想丢弃本地内容,然后拉取远程csdn分支
# 强制切到master
git checkout -f master
# 强制删除本地csdn分支
git branch -D csdn
# 切到csdn并拉取最新内容
git checkout csdn
git pull
- 场景C:删除本地有但远程已不存在的分支
git remote prune origin