You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Apple Xcode克隆指定Git分支?

How to Clone a Specific Git Branch in Xcode

Hey there, I totally get the frustration—Xcode's built-in Clone tool doesn't make it obvious how to grab a non-default branch directly. Since you already have the terminal method down, let's cover the two reliable ways to do this within Xcode or using your existing terminal knowledge:

Option 1: Clone the Default Branch First, Then Switch to Your Target Branch

This is the straightforward Xcode-native approach:

  • Open Xcode, go to Source Control > Clone, enter your repo's HTTP URL, and complete the clone (this will pull the default branch, usually master or main).
  • Once the project opens, head to the Source Control menu at the top, hover over your project name, and select Switch Branch....
  • In the popup window, expand the Remote Branches section—you should see my_dev_branch_name listed here. If it's not showing up, first run Source Control > Pull... to sync the latest remote branch info.
  • Select your target branch and click Switch—Xcode will check out that branch for you.

Option 2: Clone via Terminal, Then Open in Xcode

Since you already know how to clone the specific branch using the terminal, this might be faster for you:

  • Run your existing command in the terminal:
    git clone -b my_dev_branch_name https://gitlab.com/Username/projectname_ios.git
    
  • Once the clone finishes, navigate to the cloned folder, find the .xcodeproj or .xcworkspace file, and double-click it—Xcode will open the project directly on your target branch.

Unfortunately, Xcode's initial Clone dialog doesn't have a built-in field to specify a branch, so these are the go-to workarounds that most developers use.

内容的提问来源于stack exchange,提问作者Viral Mithani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:00:43