18

I couldn't find anything specific to this but if I missed it please let me know.

I have a file in git which needs to be there. Once pulled down each individual will need to edit it to add their own credentials to it. When edited by the individual I do not want it to show up as having been changed or anything because we want to keep the generic file without credentials in our repo. Is there an option to have a file set up as "Pull this file but never push it"? Currently the setup we have is the file is named Upload.bat_COPY_EDIT_RENAME, which hopefully makes it obvious what to do, and I have Upload.bat in the .gitignore. I'd like something more idiot proof.

I know there are options like --assume-unchanged but I don't want to have to run that every time and it seems kind of like a bandaid fix which could potentially cause problems later.

Thanks for your help!

GRobb
  • 303
  • 1
  • 8

4 Answers4

5

I would suggest a slightly different approach... You can write your Upload.bat to read from a settings file using your format of choice. Say you call it, secrets.txt. Then you can add secrets.txt to your .gitignore and commit Upload.bat with impunity. When users pull the repo, they will get Upload.bat and can create their own secrets.txt.

You might make secrets.txt have just the username and password, separated by a newline. Should be trivial to parse this way.

Kevin Burdett
  • 2,892
  • 1
  • 12
  • 19
  • I'm not sure we are looking to something that complex but that would solve the problem we have where there is a different Upload.bat for our 3 repos (Dev, UAT, Prod) and save time editing each of these files the first time you are working on that environment. – GRobb Feb 26 '16 at 15:08
2

If each person is going to rename the file, you could add Upload.bat* to your .gitignore file, and then git shouldn't track any new files with that naming scheme. More info on gitignore

DeveloperDemetri
  • 208
  • 2
  • 10
  • This is assuming that when they rename it, they will rename it to Upload.bat_myname or something that appends Upload.bat – DeveloperDemetri Feb 19 '16 at 19:46
  • They are editing the actual contents of the file and then the file gets renamed to "Upload.bat" Ideally I just have the "Upload.bat" in git which gets pulled down and then edited but never pushed back up – GRobb Feb 19 '16 at 20:15
  • If the generic file to be pulled is Upload.bat_COPY_EDIT_RENAME, then just put 'Upload.bat' (no wildcard at the end) in the .gitignore (assuming git is not yet tracking that exact file name) and it should ignore the files renamed to 'Upload.bat' while keeping Upload.bat_COPY_EDIT_RENAME. Be sure to make sure that Git is properly ignoring the file before making any commits containing it. – DeveloperDemetri Feb 19 '16 at 20:23
  • Yes but ideally I don't want to even have the "Upload.bat_COPY_EDIT_RENAME" file exist at all. Really I just want the "Upload.bat" in the repo with some rule attached to it telling git to ignore any changes to the file and don't push. What you just described is exactly how I have it setup currently and I'd like something simplified if possible. – GRobb Feb 19 '16 at 20:52
2

To my knowledge, git does not have a permanent setting to pull, but never push a file.

You could get a more reliable workaround by storing the template file in git (as you already do), and having your build script (you do have one, right?) check for the customized file. If the customized file exists, great, carry on with the build. If it does not exist, prompt the developer for their credentials and set it up. Then carry on with the build. The customized version of the file is, of course, in .gitignore.

This is essentially what you have now, but with the addition of the build script serving a reminder to the developer, instead of relying on the forgetful, oblivious human to hopefully notice and understand a funnily named file somewhere in their file system.

As an added benefit of having the script handle the creation of the customized file, it can potentially update it automatically if the template changes.

Depending on the credentials, you may want to double check to make sure that they aren't recorded to any logs when running the build script. This includes piping the output to a file.

8bittree
  • 1,769
  • 2
  • 18
  • 25
1

One approach that does not require you to add Upload.batto your gitignore is to use batch file include.

You can add a file called credentials.txt.dist to the repository with the following contents:

username=username_here
password=password_here

And then, in your batch file:

for /f "delims=" %%x in (credentials.txt) do (set "%%x")

Shamelessly taken from Batch file include external file for variables

And not tested :)

The batch script should probably do some error checking. At the very least it should generate a descriptive error message if credentials.txthas not been provided.

Community
  • 1
  • 1
jacmoe
  • 1,637
  • 13
  • 17