tags:

views:

224

answers:

2

Hi,

I am using 'git' to checkout chromium code by following this document: http://code.google.com/p/chromium/wiki/UsingGit

And it said 'Run git pull or whichever command is appropriate to update your checkout. '.

But the problem I run into is when I have local changes in my git working directory and then I run 'git pull'. It said something like XXX file can't get update (I made a change locally). I force 'git pull' to work by removing my change 'git checkout -- XXX.cpp'

Is there a way to get 'git pull' to merge automatically if possible (the svn update equivalent)?

Thank you.

+3  A: 

If you want a pull to merge with changes you have made locally, you will need to commit your changes to your local directory first. Or, stash your changes, then pull, then re-apply your stash.

William Pursell
+1  A: 

I think what you want to do is:

  1. commit all changes to your local repository
  2. do a 'git rebase'.

This is slightly better than 'svn update' in my opinion, because it will first change your local working copy to the way it was the last time you pulled or rebased from the remote, then fetch and apply new changes from the remote, and then reapply your locally committed changes. If there's a conflict between your changes and the remote changes, you'll need to resolve them and follow the prompts to continue the rebase operation.

This way the changesets should be applied in the right order.

Thanks. can I 'git stash' and then 'git rebase' and then 'git apply stash' instead?
n179911
absolutely. that's what you would do if you have changes you're not ready to commit yet, but you want to go ahead and grab any changes from the remote repo.