How to `git pull` while ignoring local changes?

Solution 1:

If you mean you want the pull to overwrite local changes, doing the merge as if the working tree were clean, well, clean the working tree:

git reset --hard
git pull

If there are untracked local files you could use git clean to remove them.

  • git clean -f to remove untracked files
  • -df to remove untracked files and directories
  • -xdf to remove untracked or ignored files or directories

If on the other hand you want to keep the local modifications somehow, you'd use stash to hide them away before pulling, then reapply them afterwards:

git stash
git pull
git stash pop

I don't think it makes any sense to literally ignore the changes, though - half of pull is merge, and it needs to merge the committed versions of content with the versions it fetched.

Solution 2:

For me the following worked:

(1) First fetch all changes:

$ git fetch --all

(2) Then reset the master:

$ git reset --hard origin/master

(3) Pull/update:

$ git pull

Solution 3:

You just want a command which gives exactly the same result as rm -rf local_repo && git clone remote_url, right? I also want this feature. I wonder why git does not provide such a command (such as git reclone or git sync), neither does svn provide such a command (such as svn recheckout or svn sync).

Try the following command:

git reset --hard origin/master
git clean -fxd
git pull