Pablo Fernandez
Pablo Fernandez

Reputation: 105220

Git pull to index

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

Upvotes: 0

Views: 800

Answers (5)

Bill Door
Bill Door

Reputation: 18926

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

Upvotes: 0

George
George

Reputation: 1285

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

git-pull --no-commit [email protected]:username/project.git

Upvotes: 0

araqnid
araqnid

Reputation: 133482

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?

Upvotes: 1

CB Bailey
CB Bailey

Reputation: 791849

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.

Upvotes: 3

yasouser
yasouser

Reputation: 5177

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.

Upvotes: 0

Related Questions