0

I have a server. My web project is hosted in GitHub. I made a cronjob in my server to pull changes from GitHub repository. But, as there is database user, password information, so I put fake user and password in GitHub repo pages. I make a script and put in the server that changes the database name and password of the file where use database user and password. The scripts run after each pulling.

But, problem is when there is local changes available git don't support pulling from remote.

I use git pull origin master that results

 * branch            master     -> FETCH_HEAD
   5aef90a..f0ef960  master     -> origin/master
Updating 5aef90a..f0ef960
error: Your local changes to the following files would be overwritten by merge:
    README.md
Please, commit your changes or stash them before you can merge.
Aborting

Now what can I do so that git ignore local changes?

Edit 1
suppose I have a file connection.php that have the fake password and user. I want to ignore that file changes.

user9719859
  • 75
  • 1
  • 11
  • Sounds to me like you want to ignore *specific* local changes - not everything... Would using the [`.gitignore` file](https://git-scm.com/docs/gitignore) help here? You could completely ignore these user/password files and not have them committed to git at all. This way it won't matter if they change. – Lix Apr 30 '18 at 14:08
  • As a side-note, the usual way to store credentials is in environment variables in the server. – msanford Apr 30 '18 at 14:17
  • You need to understand *why* this file changed. You're pulling into your _server_, right? So why did the readme change? I suspect it's the script you wrote that looks for instances of `FAKE_USERNAME` (or whatever) and replaces that with your real username in production. Just don't do that, and see my above comment. – msanford Apr 30 '18 at 14:19
  • @Lix may be your solution is simple. I add a file name. You can put a answer with gitignore. – user9719859 Apr 30 '18 at 14:29

2 Answers2

1
git reset --hard HEAD
git clean -df
git pull origin master

Basically:

  1. Reset local changes
  2. Remove any new files you've created (if needed)
  3. Pull from remote
Magd Kudama
  • 3,229
  • 2
  • 21
  • 25
0

If what you are dealing with here is login credentials (username & passwords), it might be a better idea to not have these files commited into git at all. Rather use an untracked file to store your credentials - this way you can swap it out between your local development environment and your production environment.

I would suggest adding the file holding the credentials to your .gitignore file so that git will always ignore this file and not track any changes.

You can now have one file on your local machine and a different file in production - both hold the username & passwords so your code does not need to know the difference between the two environments.


I would, however suggest that you store the username & password in their own file - not within a connection.php file since the logic there is most likely not dependant on production/local environments.

Lix
  • 47,311
  • 12
  • 103
  • 131