3

In sourcetree I would like to just check out to the remote develop branch so I can start a new feature branch in there. I'm currently in another feature branch in which I have committed and pushed all my changes.

However when I right click on remote branch origin/develop I get this: enter image description here

For some reason I can find nowhere what is the difference here. I don't want to break the repo at my new job, so I'm super careful. In GitKraken you just checkout to remote and update your local develop branch if necessary.

Steve Waters
  • 3,348
  • 9
  • 54
  • 94

3 Answers3

1

What this does is:

git checkout -b develop --track origin/develop

That will make sure the local branch develop will push to, by default, the remote branch origin/develop.

Note that with Git 2.23+, that would be git switch

git switch -c develop --track origin/develop

SourceTree has not yet integrated that new command.


I don't want to break the repo at my new job, so I'm super careful

That won't break anything: this is a local operation only.


This differ from "Checkout existing", which will only list existing local or remote branches, making it the equivalent of:

git switch <branch>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is a great answer to "What does 'Checkout New Branch' do". Could you add a sentence or two explaining how that is different from 'Checkout Existing' ? – David Cary Dec 24 '21 at 17:10
  • @DavidCary Sure. I have edited the answer accordingly. – VonC Dec 24 '21 at 17:23
0

I don't know GitKraken or Sourcetree that well, but in general you would not want to directly checkout a remote tracking branch in Git. That is, in general you would not want to do this:

git checkout origin/develop

The reason is that tracking branches, as the name implies, exist mainly to track the state of the true remote branch. But all of your local work should go into a new local branch somewhere.

So, coming back to your Sourcetree question and screenshot, I see nothing surprising there. You are saying that you want to create a new local branch develop, based on the tracking branch origin/develop. Also, you are telling Sourcetree/Git that you want this local branch to track the remote tracking branch origin/develop.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

I am not too familiar with sourcetree but usually you can create a new branch via checkout (if you add a -b to the command in a command window) so I'd asssume that checkout new branch does just that, while the other lets you checkout existing branches

NewEyes
  • 407
  • 4
  • 15