4

I am new at github and I am developing an app that has a config.php file that you must enter the database credentials.

In my github repository the file is like this:

<?php
    $host_name  = "<HOST>";
    $database   = "<DATABASE>";
    $user_name  = "<USER>";
    $password   = "<PASSWORD>";
?>

But in the website i have the file with the credentials:

<?php
    $host_name  = "myhost";
    $database   = "mydatabase";
    $user_name  = "myuser";
    $password   = "mypassword";
?>

In the .gitignore file I put the file that I don't want to push to my github repository when I am developing but what I want to do now is to ignore files when I make a pull.

What I want is to update my website from my github repository but I want to ignore the config.php file because this must be unique in each install.

How can I do it?

Denis Zavedeev
  • 7,627
  • 4
  • 32
  • 53
Roke
  • 329
  • 1
  • 3
  • 16
  • 1
    Possible duplicate of [How do I configure git to ignore some files locally?](https://stackoverflow.com/questions/1753070/how-do-i-configure-git-to-ignore-some-files-locally) – Dmitrii Smirnov Dec 20 '17 at 14:03
  • 2
    Don't put `config.php` into the repository. Create a template for the file (use a different name for it) and put the template in the repo. Add `config.php` to `.gitignore`. – axiac Dec 20 '17 at 14:04
  • I like that option, like wordpress with the wp-config-sample.php file. What i am trying to achieve is to update all my installs easy with github. That repositories are not going to make any commit. Is just a ignore only for pull commands. – Roke Dec 20 '17 at 14:12

2 Answers2

3

.gitignore is for ignoring untracked files, but you need to ignore changes in the tracked one. you could use git update-index --skip-worktree /path/to/config.php

See https://git-scm.com/docs/git-update-index#_skip_worktree_bit

Dmitrii Smirnov
  • 7,073
  • 1
  • 19
  • 29
  • 1
    But this will be ignore in all the clone repositories, I want to download this file the 1st time and then config in the clone repository the ignore option. The problem is that if i wont download this file the 1st time i wont remember to config :) – Roke Dec 20 '17 at 14:06
  • This will ignore change only in the repository you execute the command in. You can't push this change to the central repo, so it will not affect other clones. So you have the config.php with template data in the central repo, and edit it in every clone as you need, marking it with --skip-worktree – Dmitrii Smirnov Dec 20 '17 at 14:54
  • OK, now i understand. Sorry for my mistake – Roke Dec 20 '17 at 15:58
1

To stop tracking a file you need to remove it from the index. This can be achieved with this command:

git rm --cached <file>

Commit that change

git commit -am "Remove ignored config.php"

oginski
  • 354
  • 5
  • 16