user3063045
user3063045

Reputation: 2209

Github Pull Ignore Specific File

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

Answers (2)

Dan Loewenherz
Dan Loewenherz

Reputation: 11253

This means that this file has already been committed to your repo, and you're going to need to either:

  1. Rewrite your Git history as to remove any traces of it existing.
  2. Delete the file and continue.

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:

Rewrite History

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.

Delete the File

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

infused
infused

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

Related Questions