git使用 -- 不对当前分支造成影响同时拉取远程分支

130 阅读1分钟

git使用 -- 不对当前分支造成影响同时拉取远程分支

方法一:git checkout -b 本地分支名 origin/远程分支名

1、首先,获取远程所有分支
    git fetch 
 
2、创建与远程分支关联的本地分支(可以同名,也可以不同名;建议同名,方便管理)
    git checkout -b 本地分支名 origin/远程分支名

方法二:git fetch origin 远程分支名:本地分支名

1、获取远程指定分支,并创建与之关联的本地分支
    git fetch [repo] [remote_branch_name]:[local_branch_name]
// 举例:从远程 orgin 仓库的 targetBranch 分支下载到本地,并新建一个 tempBranch 分支
// git fetch origin targetBranch:tempBranch
// targetBranch 与 tempBranch 可同名,也可不同名;建议同名,便于管理)  

2、切换当前分支为本地建立的分支
    git checkout [local_branch_name]