Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore files not ignored when pulling remote changes [duplicate]

Tags:

git

gitignore

I have some files that I don't want to share between my repositories. I added them to .gitignore at the root of my project :

# Specifies intentionally untracked files to ignore when using Git
# http://git-scm.com/docs/gitignore
# ...
.idea/

And yet I keep getting this error when pulling remote changes using git pull :

error: Your local changes to the following files would be overwritten by merge :
      .idea/workspace.xml
Please, commit your changes or stash them before you can merge.
Aborting

I have seen some questions about this error message, but they were about overwriting the files. I want to ignore the changes (I don't want git to track them at all and I don't want git to change my local files).

What am I doing wrong ? Maybe the problem is I created the .gitignore file after I had already committed the files I wanted to ignore, and I need to remove them from the repo somehow...?

like image 827
yannick1976 Avatar asked Mar 15 '23 07:03

yannick1976


1 Answers

If you don't want to track them, you need to remove them from the history first, and push that removal

git rm --cached -- afile
git add -u .
git commit
git push

As soon as the file is removed locally (the --cached keeps it on your disk), your .gitignore will work.
But any git pull would get back that file if it was versioned on the remote repo side. Hence the need to push (publish) that removal, provided that you are sure every other user should not see that file anymore as well.

like image 55
VonC Avatar answered Mar 17 '23 07:03

VonC