Checkout remote git branch without pull

Answered

How do I do the equivalent of `git checkout origin/master` in the IDEA UI? I right-clicked the branch in the git pane and selected Checkout. But this proceeded to fetch the remote branch and create a local one called `master`. I don't want to fetch or pull or anything. I just want to check out `origin/master`.

0
4 comments

You are doing all right. 

Remote/Local categorization allows understanding where the branch is located. The fact that "origin/master" is displayed in both "Local" and "Remote" means that you copied the content of the branch to your local computer. All the commits will be done to Local/origin/master and once "Push" action is invoked, all the changes will be transferred to Remote/origin/master

0

But how do I check out `origin/master` without fetching it from remote?

0

The "git checkout" command can be used either to switch between local branches or to create new local branches from remote. 

There is no possibility to checkout a remote branch without copying it to local repo. 

See https://www.atlassian.com/git/tutorials/using-branches/git-checkout: 

In order to checkout a remote branch you have to first fetch the contents of the branch.

0

"git checkout origin/master" puts the repository to a detached head state, which is usually not the desired state. A local branch is usually handier, so to make it easier, when Checkout is called on a remote branch, IDE creates a local branch pointing to the same commit where the remote reference is. There is no fetch done prior to it - you can see the exact command in the Console tab, it is "git checkout -B master origin/master".

If for some reason you do want to set the repository into detached HEAD, you could use the CHeckout tag or Revision action from the branches popup, or locate the commit in the Log view and check it out from there.

0

Please sign in to leave a comment.