Extra files included in push e.g. settings.py

47 Views Asked by At

I'm trying to get with the program and embrace Git.

I've got a Django project and added a Git repo on my local machine. Have a branch called Dev.

I want to be able to push chunks of code up to my live webserver, so I have created a bare repo on the Ubuntu/Nginix/Gunicorn server.

I can push files to the remote repo using: git push live Dev:master

But, I keep knocking out my settings file. Even if I only commit one file, then run git push live Dev:master, Why does my settings file keep getting moved to live?

I've added it to the .gitignore. I've followed the instructions to clear the cache then re add everything...but everytime I do a push, my local settings file is pushed to the live server.

How do I stop this happening?

Hopefully this is just me being a muppet. Your guidance would be appreciated...

1

There are 1 best solutions below

2
dani-vta On

As @larsks has already said in the comments, Git will ignore a file only if this hasn't been tracked before. In Git, a file can fall only into one of the following categories:

  • Tracked: a tracked file is any file that at some point has been committed or just added to the Index.
  • Ignored: a file is considered ignored when the configuration file .gitginore contains a pathspec that matches the file's path.
  • Untracked: any file that doesn't belong to the tracked or ignored categories is considered untracked. Git determines untracked files by subtracting tracked and ignored files from the entire content of the working directory.

This means that, if a file has been tracked already, it can't be simply added to the .gitignore configuration to turn it into an ignored file. It should be first removed from the index (untracked), in order for the .gitignore configuration to take effect and mark the file as ignored. However, If you run git rm -r --cached . as you wrote in the comments, you will remove every tracked file from the index.

In your case, you just want to:

remove only the settings.py file

git rm -r --cached settings.py

commit your removal

git commit -m "untrack settings.py"

and then push to your remote

git push live dev:master

At this point, your remote won't have the settings.py file anymore.