.gitignore is not ignoring directories

What I did:

I think there were some weird configurations from the github gui that caused this issue and prevented me from being able to easily use git from command line or even git-bash.

  • Specify private SSH-key to use when executing shell command with or without Ruby?
  • Git merge (or rebase) branch but only to a specific commit
  • mac os x / github / multiple public keys?
  • With git, how do I save a topic branch after the parent remote branch was rebased?
  • How can I move all my modification to a branch
  • How to get all branches with someone’s commits using git?
  • I ended up just uninstalling github and git then reinstalling just git for windows. I now have everything running off the command line(except ssh which I run from git-bash). Much easier and more reliable that the github gui.

    Thanks to mu 無 for taking the time to try to figure this out. I didn’t end up using his answer, but if I hadn’t needed to do a reinstall of git it would have been what I needed to do.


    I am using the github gui on my local machine. I just noticed that a commit I was about to make was going to update all of my recently update node modules. I set up my .gitignore to ignore the entire node_modules/ directory.

    I’m not sure what to do about this. All the file types I included in .gitignore were ignored. It’s just the directories that it seems to ignore.

    Here is my .gitignore file:

    #################
    ## Sublime Text
    #################
    
    *.sublime-project
    *.sublime-workspace
    
    #################
    ## Images
    #################
    
    *.jpg
    *.jpeg
    *.png
    *.gif
    *.psd
    *.ai
    
    #################
    ## Windows detritus
    #################
    
    # Windows image file caches
    Thumbs.db
    ehthumbs.db
    
    # Folder config file
    Desktop.ini
    
    # Recycle Bin used on file shares
    $RECYCLE.BIN/
    
    # Mac crap
    .DS_Store
    
    #################
    ## Directories
    #################
    
    dev/
    cms/core/config/
    node_modules/
    

  • Windows Git - picking up the pieces
  • Fixing github rails deployment
  • Viewing GIT history of moved files
  • Giving access to parts of a github repository
  • Cloning Git Repositroy using ssh
  • Why does git ls-files --ignore require exclude patterns?
  • 3 Solutions collect form web for “.gitignore is not ignoring directories”

    You have a spelling mistake in the ignore rule – You are ignoring node_modules/ instead of node_module/.

    EDIT

    Since the node_modules directory is already tracked as part of the repository, the .gitignore rule will not apply to it.

    You need to untrack the directory from git using

    git rm -r --cached node_modules
    git commit -m "removing node_modules"
    

    You can run the above 2 in git-bash.

    After this, the .gitignore rule will ignore the directory away.

    Note that this will remove the directory node_modules from your other repos once you pull the changes in. Only the original repo where you made that commit will still have the node_modules folder there.

    If the files are already tracked the .gitignore file will not override this. You will need to use git rm --cached <files>

    See the full details on git rm at
    https://www.kernel.org/pub/software/scm/git/docs/git-rm.html
    I ran into this once or twice myself early on with git and it was not quite what I expected either.

    If you work with node projects, I like this .gitignore:

    # See http://help.github.com/ignore-files/ for more about ignoring files.
    
    # dependencies
    node_modules
    
    # testing
    coverage
    
    # production
    build
    
    # misc
    .DS_Store
    .env
    npm-debug.log
    
    Git Baby is a git and github fan, let's start git clone.