secondman
secondman

Reputation: 3277

How Do I untrack or ignore files without having them deleted in Git?

I'm a bit confused on how to use ignore and exclude with git.

I have a repo with 2 branches, master and production.

These 2 branches have config files that need to be different one is for the development server and one for the production server.

Git documentation states that ignore and exclude does not operate on tracked files. But if I untrack them, then they get deleted both locally and on the remote repo.

If I only apply locally either option, then when I merge or rebase any changes in other files, the configs are overwritten with the configs from the other branch.

I'm currently using Tower on Mac OSX.

Upvotes: 0

Views: 84

Answers (1)

user229044
user229044

Reputation: 239311

Use --cached to remove the file from the index, but not the disk:

$ git rm --cached my_file

$ git status

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    my_file

Don't forget to commit your changes:

$ git commit -m "Removed a my_file

Upvotes: 4

Related Questions