1

I have a project in Git that I'm going to install in many PC. There's a configuration file named config.ts and has the following structure:

export var config = {
   apiUrl: "",
   local: "",
   scannerUrl: "",
   reportPrinterUrl: ""
}

What I need is to create the file if not exists when I execute the git pull origin master command, but stop tracking it when it's modified so it can be modified in any pc and the configuration won't be pushed or erased in the next pull.

I've read some questions and articles but I've seen many options like git stash, --asume-unchanged and still not pretty sure how to do it.

(Sorry for bad english)

EDIT

The most simple way that I've found to just forget about the file is to execute this command in every pc

git update-index --assume-unchanged <file>

Credits from here

EDIT 2

Like torek said in the comments, the current best solution is to create the "template" file and name it "config.blank.ts" (or something like that) and then add to .gitignore the "config.ts" file. So the procedure should be cloning the repo and then copy the file to config.ts and then modify it.

  • Add this file to your .gitignore – marcusshep Aug 09 '17 at 17:12
  • but that only works if the file has never been commited, and if that's the case then i wont be able to get the "clean" version of it the first time for the structure – Eduardo González Aug 09 '17 at 17:13
  • 4
    In general, the right way to do this is to omit the actual configuration file entirely, and commit instead a *sample* configuration file, that users of the software copy and modify to local requirements during installation. You can even have your program do this installation automatically, and/or read the sample / default file first, then read any *overrides* from the (never-committed, in-`.gitignore`) *local* configuration. – torek Aug 09 '17 at 17:27
  • 2
    Use `--skip-worktree`, not `--assume-unchanged`. Both bits generally have the same effect but `--skip-worktree` has a different *intent:* it tells Git to *skip* the worktree version, while `--assume-unchanged` tells Git that *testing* the work-tree version is too expensive to do if there's no call to do it, but that Git *could* test the work-tree version if it wanted to. (But it's far better to never commit the local configuration in the first place.) – torek Aug 09 '17 at 17:33

1 Answers1

0

Simply don't push the changes to your config file.

When you clone this project onto different local machines, you want to make your necessary changes to the config file. In order to keep these changes from being pushed back to the remote repository, don't add or commit these changes to your git history.

Say you have files x, y and z. You make changes to all three of these files but you don't want to push the changes made in file y.

git add /path/to/x
git add /path/to/z
git commit
# etc

Add to your .gitignore

If say your config file has been adding in previous commits, you would have to run the following.

echo "config.ts" > .gitignore
git rm --cached config.ts

If you then run a git status, you'll see that your config file has been deleted. This is only deleted on your git-index, not actually deleted on your machine.

marcusshep
  • 1,916
  • 2
  • 18
  • 31