Git ignore local file changes

Git

Git Problem Overview


I've tried both

git update-index --assume-unchanged config/myconfig

and

editing .git/info/exclude and adding config/myconfig

however when I do git pull I always get:

>Updating 0156abc..1cfd6a5 >error: Your local changes to the following files would be overwritten by merge: config/myconfig Please, commit your changes or stash them before you can merge. Aborting

What am I missing?

Git Solutions


Solution 1 - Git

git pull wants you to either remove or save your current work so that the merge it triggers doesn't cause conflicts with your uncommitted work. Note that you should only need to remove/save untracked files if the changes you're pulling create files in the same locations as your local uncommitted files.

Remove your uncommitted changes

Tracked files
git checkout -f
Untracked files
git clean -fd

Save your changes for later

Tracked files
git stash
Tracked files and untracked files
git stash -u
Reapply your latest stash after git pull:
git stash pop

Solution 2 - Git

You most likely had the files staged.

git add src/file/to/ignore

To undo the staged files,

git reset HEAD

This will unstage the files allowing for the following git command to execute successfully.

git update-index --assume-unchanged src/file/to/ignore

Solution 3 - Git

You probably need to do a git stash before you git pull, this is because it is reading your old config file. So do:

git stash
git pull
git commit -am <"say first commit">
git push

Also see git-stash(1) Manual Page.

Solution 4 - Git

If you dont want your local changes, then do below command to ignore(delete permanently) the local changes.

  • If its unstaged changes, then do checkout (git checkout <filename> or git checkout -- .)
  • If its staged changes, then first do reset (git reset <filename> or git reset) and then do checkout (git checkout <filename> or git checkout -- .)
  • If it is untracted files/folders (newly created), then do clean (git clean -fd)

If you dont want to loose your local changes, then stash it and do pull or rebase. Later merge your changes from stash.

  • Do git stash, and then get latest changes from repo git pull orign master or git rebase origin/master, and then merge your changes from stash git stash pop stash@{0}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2395365View Question on Stackoverflow
Solution 1 - GitNick McCurdyView Answer on Stackoverflow
Solution 2 - GitEricView Answer on Stackoverflow
Solution 3 - Gituser3858653View Answer on Stackoverflow
Solution 4 - GitrashokView Answer on Stackoverflow