Max Basmanov
Max Basmanov

Reputation: 53

exclude files from pushing and pulling

I have a remote repository that is mirrored to a development site and downloaded to my local machine to work with. When I push changes they update the site by hooks.

Update The thing i need: Repository holds whole project with working "configuraion.php" for development site (working online resource for testing); Any developer can pull the roject and change the only two path variables in configuration.php to run it; After that this file should not be commited to repository and should not be overwritten when pulling changes.

But I get errors pulling from repository. I have tried:

But when I try to pull changes (made by others) from repository I get the following:

error: Your local changes to the following files would be overwritten by merge:
    configuration.php
Please, commit your changes or stash them before you can merge.
Aborting

Tried to add to ".git/info/exclude" but no visible effect.

What am I doing wrong?

Upvotes: 4

Views: 3406

Answers (2)

vgoff
vgoff

Reputation: 11343

It is pretty common that configuration files are necessary for a project. But it is also pretty common to have a sample file provided that gives great information for a standard configuration.

You can name this file configuration.php.sample with directions to copy this file to configuration.php and change the information in the file where it needs to be changed.

If it is possible to read in information to supplement this information, then perhaps instruction to create a 'local_config.php`.

In either case, the configuration files don't get tracked in the repository, but the samples do. This allows for the information to be updated, while the locally changed files are simply not tracked.

Otherwise, if you make changes to a file that you don't want to get pushed up, you can stash your changes (This is a great argument for never using git add . and being responsible in indicating the files that you want added every time) do your repository changes, and your pushes and pulls and then do a git stash pop to get your specific local changes back.

And your helpful message from git even suggests you do a stash. It may be as simple as just doing this, to get what you want if your want is unique to you, and not to all developers in your project.

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522712

Could it be the case that the file configuration.php is still being tracked by other people? If so, then your remote repository would contain this file and when you go to do a git pull Git would try to bring this file into your local repository. Despite that you have untracked the file, Git appears to be trying to bring it in from the remote.

Update:

It doesn't make sense in Git's model for a remote file to be ignored. Hence, if you insist on maintaining the configuration.php file in the remote repository, then you should not be using this file in your local setup. One easy workaround would be to keep a different local PHP config file (e.g. configurationLocal.php) and run that for your local testing.

So your workflow might be something like this:

  1. git pull which will obtain the latest configuration.php file
  2. Copy configuration.php to configurationLocal.php
  3. Add configurationLocal.php to your .gitignore file so it never gets tracked
  4. Use configurationLocal.php for all of your unit testing, etc.

During subsequent calls to git pull there could be conflicts with configuration.php, but it won't matter. In case of conflicts, you can simply accept the server's version, and then update your configurationLocal.php script as needed.

Upvotes: 3

Related Questions