Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to `git pull` while ignoring local changes?

Tags:

git

git-pull

Is there a way to do a git pull that ignores any local file changes without blowing the directory away and having to perform a git clone?

like image 856
markdorison Avatar asked Nov 11 '10 17:11

markdorison


People also ask

Will git pull override my local changes?

git pull --force it feels like it would help to overwrite local changes. instead, it fetches forcefully but does not merge forcefully ( git pull --force = git fetch --force + git merge ). Like git push, git fetch allows us to specify which local and remote branch we want to work on.

How do I ignore an error on git pull about my local changes?

git reset --hard origin/<branch> did help!

How do I override local changes in git?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.


1 Answers

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.

like image 100
Cascabel Avatar answered Sep 19 '22 23:09

Cascabel