user3467349
user3467349

Reputation: 3191

Git keep file in Local branches but remove from repo

I thought there would be an obvious solution but can't seem to find it. I have a repo with a configfile that changes from machine to machine -

I I do git rm --cached myconfig.conf and make a file called myconcif.template.conf - this mostly works, but if I switch branches locally and then switch back myconfig.conf ends up getting removed.

What I want is to be able to keep myconfig.conf changes committed locally, but have them ignored for both repository push and pull.

Upvotes: 0

Views: 255

Answers (1)

ffflabs
ffflabs

Reputation: 17481

After doing git rm --cached myconfig.conf you need to add it to the .ignore file.

Adding it to the ignore file means that the file will be ignored not only for pull and push, but for switching branches too.

If you want local myconfig.conf to change with each branch without having it versioned, I'm afraid you can't.

Edit: sometimes git seems to be stubborn about this procedure, so a dirty workaround is just:

  • Copy the file to another location out of the repo.
  • Delete it with git rm
  • Add it to the .gitignore
  • Commit and push the deletion and the changed .gitinore
  • Do the same in all your working branches locally and in the repo
  • Make sure all your branches are in sync with the remote
  • When you're sure the file isn't coming back after pulling or switching branches, you can safely move the copied version to your repo folder.

Upvotes: 1

Related Questions