0

Is there a way to pull remote changes to the index instead of directly creating a new commit?

Ideally it would be like applying a patch with the remote contents, but not modifying your local history.

Thanks

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232

5 Answers5

3

I'm not quite sure what your intended work flow is, but you can fetch remote changes without affecting the current branch or index.

git fetch

You can then merge the fetched changes into the current index without setting up a merge commit, but this is a fairly obscure and unusual thing to want to do.

git read-tree -m HEAD origin/remote-branch

The two tree version is best if the remote branch is a fast-forward of your current HEAD, if not then the three way merge option may be better.

git read-tree -m $(git merge-base HEAD origin/remote-branch) HEAD origin/remote-branch

Read the man page for git read-tree for the details on the differences.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
1

The problem would then be the next you you pull remote changes, from what point in the remote's history should it generate the patch? This is exactly the problem that merging is intended to solve, the merge commit indicates which remote version has been applied to your local branch so far.

Having said that, if you do git fetch and git merge --no-commit, the merge will be done in your workspace (and index) but not committed, and the metadata will be left in a state so that when you do commit, it will be marked as a merge commit. Is that what you need?

Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
araqnid
  • 127,052
  • 24
  • 157
  • 134
  • I suspect this is what the OP actually wants (merge to index *and* work tree, but not commit). Note that you can just do `pull --no-commit`; it's passed through to `merge`. – Cascabel Jan 10 '11 at 00:40
0

git fetch will fetch the changes from the remote but not merge it with your master branch. It will be in the remote tracking branch. You can then merge it manually. A git pull performs both these operations together.

yasouser
  • 5,113
  • 2
  • 27
  • 41
0

I keep coming to this page and missing the right answer because it's in a comment.

git-pull --no-commit git@github.com:username/project.git
George
  • 1,265
  • 1
  • 10
  • 8
0

Take a look at this answer. You might want to adjust your configuration to avoid the merge commits.

Community
  • 1
  • 1
Bill Door
  • 18,272
  • 3
  • 32
  • 37