📅  最后修改于: 2023-12-03 15:00:56.176000             🧑  作者: Mango
如果您想从远程仓库中获取一个新分支并在本地进行创建和跟踪,则可以使用 git pull
命令。
origin
。git remote add origin <remote_repo_url>
git branch -r
git fetch
命令从远程仓库中拉取分支,并在本地创建和跟踪该分支。git fetch origin <remote_branch_name>:<local_branch_name>
git pull
命令。git pull origin <remote_branch_name>
以一个名为 myproject
的仓库为例,下面的操作将从该仓库的远程分支中获取一个名为 new-feature
的新分支,并在本地创建和跟踪该分支。
# 将远程仓库添加至本地仓库
git remote add origin https://github.com/myusername/myproject.git
# 获取分支列表
git branch -r
# 从远程仓库拉取分支并在本地创建和跟踪该分支
git fetch origin new-feature:new-feature
# 获取分支的最新代码
git pull origin new-feature
请注意,如果您从远程仓库拉取新分支之前已经运行过 git fetch
命令,则无需再次运行该命令。