Reputation: 2209
In my GitHub repo I have a file www/settings.js which is where custom settings are stored. I added this file to .gitignore but I'm still getting an error when attempting to commit changes on my local repo:
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
modified: www/index.html
modified: www/settings.js
no changes added to commit
How do I prevent git from attempting to keep www/settings.js up to date locally?
Upvotes: 0
Views: 87
Reputation: 11253
This means that this file has already been committed to your repo, and you're going to need to either:
In either case, you will need to back up the contents of the file in another location before continuing. Here are the instructions for each case:
cp www/settings.py www/settings.py.backup
git filter-branch --index-filter 'git rm --cached --ignore-unmatch www/settings.js' HEAD
# Copy the original file back
mv www/settings.py.backup www/settings.py
This will remove all traces of the file from any commit you've made to the repo.
cp www/settings.py www/settings.py.backup
git rm --cached www/settings.py
# Commit the change
git ci
# Copy the original file back
mv www/settings.py.backup www/settings.py
Upvotes: 1
Reputation: 24357
In addition to ignoring the file in .gitignore, you should remove it from the repository and keep your local copy of it:
git rm --cached www/settings.js
git commit -m 'do not track changes to local settings'
git push
Upvotes: 0