提交代码
- git status
查看那些文件代码有变动 - git add
把文件添加到本地git缓存中
git add . | 添加全部文件 |
git add srv/main/java/com/yanh/test/Test.java | 添加指定文件 |
- git commin -m "备注"
推送到本地git库中
- git pull
取远程分支与本地分支合并
git pull | 已绑定远程分支话可简写 |
git pull origin feature_yanh | 获取指定远程分支到本地分支 |
- git push
把git本地分支的代码推到远程分支上
git push | 已绑定远程分支话可简写 |
git push origin feature_yanh | 把本地分支代码推送到指定远程分支 |
- git merge
合并两个分支的代码,需先切换到目的分支
git merge feature_yah | 把feature_yanh分支的代码合并到当前分支 |
- git push
merge完成之后需要push提交merge
其他操作
- git checkout 另一个分支
切换分支
git checkout feature_yanh | 切换到feature_yanh分支 |
git checkout -b feature_yanh origin/feature | checkout远程的feature分支,在本地起名为feature_yanh分支,并切换到本地的feature_yanh 分支 |
-
git fetch
与 git pull 同作用,只是不会自动 merge -
git remote
操作远程分支
git remote update origin -p | 更新远程分支 |
git remote -v | 查看所有的远程分支 |
git remote rm 分支名 | 删除远程分支 |
- git branch
查看分支
git branch | 查看本地分支 |
git branch -r | 查看远程分支 |
git branch -a | 查看全部分支 |
有时远程分支会有缺失
先使用 git fetch origin 或者 git remote update origin -p 在查看