工作中非常常见的远程/本地仓库分支操作
-
本地分支操作 | 分支创建/切换
# 本地创建新分支,并切换至该分支 git checkout -b 'new local branch' # 等同于上述命令 git branch 'new local branch' && git checkout 'new local branch'
-
远程分支操作 | 分支查看/创建
# 查看远程所有分支 git branch -rv # 查看本地分支和远程分支关联情况 git branch -vv
-
远程仓库操作 | 仓库查看/添加
# 查看远程仓库 git remote # 添加远程仓库 git remote add 'alias of remote rep' 'url' # 获取远程最新代码到本地 git fetch 'alias of remote rep' 'branch of remote rep'
-
远程分支和本地分支的映射关系
# 建立当前分支与指定远程分支的追踪关系,但不会拉取代码。参数"-u"和"--set-upstream-to"同样用处。 git branch -u 'alias of remote rep'/'branch of remote rep' # 等同于上述命令 git branch --set-upstream-to 'alias of remote rep'/'branch of remote rep'
💡
git fetch
和git pull
的区别在于前者不会直接merge
, 而后者会在获取最新代码后直接merge