Difference between checkout existing and checkout new branch in Sourcetree

老子叫甜甜 提交于 2020-01-23 18:20:33

问题


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:

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.


回答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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/55263244/difference-between-checkout-existing-and-checkout-new-branch-in-sourcetree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!