git clone <REPO_URL>
git init
git remote add origin <REPO_URL>
git fetch
git checkout develop
git pull
git branch <BRANCH_NAME>
git branch <BRANCH_NAME> origin/<ORIGIN_BRANCH_NAME>
git checkout <BRANCH_NAME>
git push --set-upstream origin <BRANCH_NAME>
分支合并(如把feature/test合并到develop)
git checkout develop
,git pull
git merge test --no-ff
,–no–ff可以保留原分支历史, git merge
删除分支
git branch -d <BRANCH_NAME>
git branch -r -d origin/<BRANCH_NAME>
提交代码流程:本地工作区文件 -> git暂存区(add指令
)-> git本地仓库(commit指令
) ->git远程仓库(push指令
)
git区域图
暂存区文件的添加和移除(add指令
、rm指令
)
git add .
git add <FILE_PATH>
git rm --cached <FILE_PATH>
,这里不加–cached会把文件一起从工作区删除commit指令
) git commit -m '提交信息'
git log
、查看树状图:git log --graph
git status
推送到远程仓库(pull指令
、push指令
)
push代码前一定要pull先:git pull --rebase
,pull默认的方式是用merge,这里建议用rebase,才不会出现菱形结构(如图CDGFEC),
也可以修改 C:\Users\用户名.gitconfig 配置rebase = true,直接使用git pull
推送本地库更改到远端库(已提交的内容不能反悔):git push
git stash
,保存工作区和暂存区的改变(手头功能无法提交,又影响切换分支、修改其他功能等时候常用) git stash
git stash pop