Git: How to add files and subfolders in a gitignore'd folder

Suppose I have a folder




{a},{b},{c},{d},{e},{f},{g} – are hash keys, any alpha-numeric characters are possible

abcdefghijklmnopqrstuvwxyz - is a hashed filename

I don’t want git to track it neither on development machines nor on production server, so it is added to a .gitignore file.

Suppose now I’ve created a branch “Backups” on the production server where I want to store the state of the project at different moments of time.

To do that I need to ‘add’ and ‘commit’ all files of a project including those which are under .gitignore

Note: Changing .gitignore is a bad idea in general because

  1. It might cause problems when pulling changes from develment branches

  2. In a heavily loaded and recently changing project it will be a problem to checkout other branch because of new untracked files that are added each second right after you finished adding and commiting the previous ones

  3. etc…

So the question: How do I force git to ‘add’ files that are under .gitignore ad then ‘commit’ them without actually changing .gitignore?

  • Mac OS X 10.10 merge tool git bugs
  • Create Stash repo via Rest API?
  • How to remove permission of commit on master branch
  • Vim not highlighting whitespace in git patch
  • zsh - show if git branch have unpushed commits
  • Git branching model strategy
  • git-update-server-info not sufficient to clone remote repo?
  • Are there any text user interfaces (TUI/ncurses) frontends for mercurial and git?
  • 2 Solutions collect form web for “Git: How to add files and subfolders in a gitignore'd folder”

    From the git-add manpage:

       -f, --force
           Allow adding otherwise ignored files.

    .gitignore allows not only to ignore but also to re-add, it’s the exclamation mark:


    You will find this properly documented here, if you’re in shell type git help gitignore.

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