如何使用Sourcetree从已有远程分支创建上游远程分支?
Hey there! I totally get how Git and Sourcetree can feel overwhelming when you're just starting out—let me break down exactly how to do this step by step, no jargon overload promise.
First, sync your local repo with the remote
Open your repository in Sourcetree, then hit the Pull button at the top toolbar. This makes sure you have the very latest version of the existing remote branch on your local machine, so you're starting from the right place.Check out the existing remote branch locally
Look at the left-hand Branches panel—you'll find your remote branches under theremotesfolder (e.g.,remotes/origin/main). Right-click that existing branch and select Checkout. This creates a local copy of the branch and switches your workspace to it.Create your new local branch
With the existing branch active, click the Branch button at the top. Give your new branch a descriptive name (likefeature/payment-integration), double-check that the Based on field is set to your current checked-out branch, then click Create Branch. You'll now be working on this new local branch.Push the branch to the remote and set upstream
Click the Push button next. In the popup window, you'll see your new local branch listed under Local Branches—make sure its checkbox is ticked. You'll notice an option (sometimes auto-selected) that links this local branch to the remote one, essentially setting the upstream. Just hit Push, and Sourcetree will create the new remote branch and tie it to your local version automatically.Double-check it worked
Head back to the Branches panel—your new branch should now appear under both Local and theremotesfolder. If you right-click the remote branch, you'll see it's linked to your local branch, which means the upstream is set correctly.
Quick pro tip: If you ever forget to set upstream during the initial push, just right-click your local branch later, select Push, and in the popup check the Set upstream box before pushing again. That'll fix it right up!
内容的提问来源于stack exchange,提问作者coolly




