How to add /.vim directory and all of it's subdirectories to a git repository

Here’s my ~/.gitignore file:

# ignore everything
*
# don't ignore these files
!*.vimrc
!*.vim
!*.bashrc
!.gitignore

The problem is that .vim is a directory and I want to include it (and all of its sub folders) in this git repository; however, they aren’t included with my current gitignore file.

I’ve also tried this:

# ignore everything
*
# don't ignore these files
!*.vimrc
!*.vim/
!*.bashrc
!.gitignore

and this:

# ignore everything
*
# don't ignore these files
!*.vimrc
!*.vim/*
!*.bashrc
!.gitignore

How can I ensure that the vim directory and its subdirectories are included in this git repository?

  • Vim Fugitive: Gblame reblame options
  • vimdiff between current and previous git version of a file
  • git: editing a file cause ^M to appear when using git diff
  • Line-endings in go-language source files using vim and git on MS-Windows
  • Cannot commit my .vim contents to my git repo
  • Change Fugitive's Gstatus window height
  • How can I commit files currently displayed in Vim with fugitive?
  • `git add` adds ^M to the end of every line
  • 3 Solutions collect form web for “How to add /.vim directory and all of it's subdirectories to a git repository”

    Try !.vim/ or !.vim/**

    https://git-scm.com/docs/gitignore has this tip:

    A trailing "/**" matches everything inside. For example, “abc/**” matches all files inside directory “abc”, relative to the location of the .gitignore file, with infinite depth.

    You can always use the -f flag to add it to git

    -f/--force

    Allow adding otherwise ignored files.

    git add -f .vim
    

    Assuming your version of git is later than 1.8.4 then the following should work in your gitignore file.

    #ignore everything
    *
    #don't ignore these files
    !*/
    !.vim/**
    

    The * pattern ignores everything including the parent directory and it is not possible to re-include anything if it’s parent directory is excluded.

    The pattern !*/ re-includes all directories, allowing you to use the double-wildcard !.vim/** to re-include everything under the .vim directory.

    This has been tested to work under git version 2.5.0

    Git Baby is a git and github fan, let's start git clone.