Search code examples
gitatlassian-sourcetreegit-checkout

Difference between checkout existing and checkout new branch in Sourcetree


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.


Solution

  • 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>