Skip to content

Instantly share code, notes, and snippets.

@tqheel
Created July 19, 2012 16:09
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tqheel/3144984 to your computer and use it in GitHub Desktop.
Save tqheel/3144984 to your computer and use it in GitHub Desktop.
Prevent ASP.Net Web.Config From Being Committed By Git
#Run this to reverse ignoring of changes to web.config so it gets committed.
git update-index --no-assume-unchanged path_to_file/web.config
#Run this in GitBash to temporarily ignore changes to web.config so it does not get committed.
git update-index --assume-unchanged path_to_file/web.config
@tqheel
Copy link
Author

tqheel commented Jul 19, 2012

When working with another developer on the same app and working off of a localhost db, I get tired of having to change my connection string in web.config every time he changes his conn string to match his local environment (Note: the other dev has to follow this practice as well or this approach will not work).

So to avoid that I use these two GitBash scripts to toggle the tracking of web.config. That way I only commit web.config when there are changes to the file other than dev conn string changes.

Now, you will get an error when you do a pull from the repo when the other dev has made substantive changes to the config file, if you are still running in the "ignore mode" set by ignore-config.sh script. However, just run commit-config.sh, tell git to commit your local changes and then do your pull from the repo again. You may get a merge conflict, so work through that as you normally would, commit your changes, then run ignore-config.sh again to stop tracking your config changes going forward.

@yvzkr
Copy link

yvzkr commented Apr 15, 2020

if you reset this setting use;

git update-index --really-refresh

@tqheel
Copy link
Author

tqheel commented Apr 15, 2020

Wow. The Internet is fascinating. I don't even remember writing this or what project I was referring to at the time.

@tqheel
Copy link
Author

tqheel commented Apr 15, 2020

But thanks for the tip @yvzkr!

@yvzkr
Copy link

yvzkr commented Jun 4, 2020

But thanks for the tip @yvzkr!

haha your welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment