Ignoring a File That You Have Already Started Tracking in Git

These are the confessions of GitHub for Windows user who is new to Git. I’m using GitHub to make code available from my demonstrations, presentations and workshops and am generally enjoying Git for source control.

Today I put in about 30 minutes (and a few too many commits) into trying to prevent AuthConfig.cs from being committed to my project on GitHub. AuthConfig.cs is a new file in the basic Asp.Net MVC 4 template that allows for seamless OAuth integration with sites like Facebook and Twitter. I need the file in the repository, but I don’t want to share my API keys.

As a side note, I’ve long been a fan of Asp.Net authentication and authorization and the recent overhaul is sexy with OAuth awesomesauce. Check out my link at the end of this post to see what I mean.

Just Trying to Git It

Yes, I’m still a relative rookie to Git and there are some things that I haven’t wrapped my head around, but most of the time I at least have the vocabulary I need to find out what was going on.

EDIT: Ready a rookie! You don’t have to ignore if you’re telling Git to “assume-unchanged”.

First off, ignoring doesn’t work on files that are already tracked. This means that if you’ve created a file before you’ve added your ignore rule, then Git is already “tracking” the file and it doesn’t matter if you try to add an ignore rule after the fact.  At this point – which is where I was – you need to add your ignore rule and then instruct Git to assume that the file is unchanged.

I added the following line to my ignore file, which is easily accessed through the GitHub for Windows UI, under settings.

      # Membership
      AuthConfig.cs

image

The last step was to tell Git that we don’t really want to submits changes anymore.  To do this, right-click on your repo in GitHub for Windows and select “Open a Shell Here”:

image

Finally, type this in the shell that opens up, replacing the project name and path as appropriate to your AuthConfig.cs file:

    git update-index --assume-unchanged YourProject\App_Start\AuthConfig.cs

This is really just a 2 second process, but I wish I knew it 30 minutes ago. Hope this helps out!

Link-o-liciousness

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by sweet Captcha