2

In our application, there's a small handful of files we keep changed in a specific way to make logging in through our local host easier - in our previous source control system, we'd keep them hijacked so that they would stay that way and not affect the source code.

Now we're migrating to GIT, and I would like to keep these changes in my local that make local changes easier to test, but I don't see any obvious way to keep 'hijacked' files in Git.

How can I keep my changes in my local repository, and not distribute them when I commit/push?

Zibbobz
  • 725
  • 1
  • 15
  • 41
  • Couple of things to evaluate would be git stash (with git stash pop) or including the files explicitly in .gitignore – unigeek Feb 27 '19 at 18:27
  • Possible duplicate of [Keep file in a Git repo, but don't track changes](https://stackoverflow.com/questions/9794931/keep-file-in-a-git-repo-but-dont-track-changes) – phd Feb 27 '19 at 20:06
  • https://stackoverflow.com/search?q=%5Bgit%5D+application+config – phd Feb 27 '19 at 20:06
  • @phd I think the question is different, but the answer is definitely the same - I'm not sure if that makes it a duplicate or not. – Zibbobz Feb 27 '19 at 20:39

2 Answers2

2

Suppose you have a configuration file already checked in that is meant for deployment, and when you checkout the repo, you want to replace that configuration with your own for local development. However, you don't want to have to create another branch and fiddle with merging. You just want to push/pull. I get that. What you need to do is to stop tracking new updates to a file that's already been tracked. Just run the following on your local repo:

git update-index --assume-unchanged [path-to-config-file]

If you want to reverse, just use --no-assume-unchanged to make git start detecting changes again.

Note: You have to remember this setting in case you start running into problems like "Why is it failing in deploy? My local build is running properly."

alans
  • 1,022
  • 9
  • 17
  • Thank you, this is *exactly* what I was looking for! I assume, if I ever *do* need to make a permanent change, that I can just start tracking changes, alter the file to match what should be in my remote repo, and then make the change I want? – Zibbobz Feb 27 '19 at 18:57
  • @Zibbobz Yes. Once you turn off that option for the file and you will see git detect the changes made to it so you can stage & commit it. – alans Feb 27 '19 at 19:12
  • Super--was not aware of this! I have learned to rely on git to tell me what I've changed and I don't have a need for this usage pattern with my particular toolset. Good to know, however! – unigeek Feb 27 '19 at 19:33
0

Not sure if I understand your question correctly. Based on my understanding, if you just create a local git branch without setting any up-stream and do not push it, the branch will only be kept locally.

Ren Chen
  • 155
  • 5