How to git fetch and checkout without creating a remote branch locally?

Another neat method (at least on/from Github) is fetching like this:

git fetch repo pull/7324/head:pr-7324

Where:

repo points to the remote repo, e.g. git://github.com/xxx/xxx.git.

pull/7324/head is the remote pull request.

pr-7324 is the local pull-request branch.

Then you can use the local PR branch to do whatever you want with it.

Source: adapted from this discussion.


For any Git server:

git fetch git://host.com/path/to/repo.git remote-branch-name:local-branch-name
git checkout local-branch-name

You want to use FETCH_HEAD.

whenever you run git fetch ... a magic reference called FETCH_HEAD is created.

Try for example:

git fetch git://github.com/xxx/xxx.git branch_name && git merge FETCH_HEAD