Search code examples
gitmergegit-checkoutpullgit-fetch

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


Use Case: I have some repo on GitHub, someone forked it and added new feature and initiated pull request. I can't automatically merge it because there are some minor problems I would like to fix first.

It's one-time activity I'll never need this remote repository, so I don't want to create local remote branch.

Basically I would like to do:

  1. copy files from remote repository and rewrite my own (without any git-related information).
  2. see difference with my current head.
  3. fix something and commit it.

How to do that?

git checkout git://github.com/xxx/xxx.git doesn't works at all (fail with error)

git fetch git://github.com/xxx/xxx.git works but doesn't update anything


Solution

  • 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