How to force git to add dotfiles to repository

53,482

Solution 1

git add . and git add dir/.dot work fine for me with the unadorned 1.6.6.1 and 1.7.0 versions of Git that I have handy right now.

% git --version
git version 1.6.6.1
% git ls-files -o
.baz/baz
.foo
bar/.bar
quuux/quuux
quux
% git add .
% git ls-files -o
% git ls-files 
.baz/baz
.foo
bar/.bar
quuux/quuux
quux

What version of Git are you using? Are your subdirs actually submodules (which are managed independently)?

“dot files” are not excluded by default, but maybe some bit of configuration on your system, repository, or working tree has them set that way. If they show up in git ls-files --exclude-standard -oi then they are being ignored and "!.*" is the right way to ‘unignore’ them. But to be effective, that pattern has to be in the right place. Ignores are processed in this order:

  • .gitignore of the immediately containing directory, then
  • .gitignore of the parent directory (each parent, up to the repository root), then
  • $GIT_DIR/info/exclude, then
  • the file reported by git config core.excludesfile (which could be set by
    • $GIT_DIR/config,
    • $HOME/.gitconfig, or
    • the system config file (try GIT_EDITOR=echo git config --system --edit to get its pathname)).

When a pathname matches a pattern in one file, subsequent files are not consulted. The last match in each file “wins”. A pattern in $GIT_DIR/info/exclude can never override a pattern in a .gitignore file. So, if the files are being ignored (per git ls-files --exclude-standard -oi) and if "!.*" in $GIT_DIR/info/exclude is ineffective, then check all the applicable .gitignore files for the culprit.

Solution 2

You can add them specifically by pathname, e.g.,

git add */.*

or

find . -name '.[a-z]*' -exec git add '{}' ';'

(It's good to be careful with the -name because you don't necessarily want to pick up every directory with its . entry.)

But by far the easiest way to do this is with git gui. Just click on the files.

Solution 3

If there are only few .dotfiles you need to add, I recommend using -f flag since simple git add .yourDotFile does not work on git version 2.28.8 and you do not want to mess with global .gitignore. Therefore use git add .yourDotFile -f

Solution 4

Interestingly under windows 10 with git version 2.12.0.windows.1 running under "Git-Bash" an "git add .*" fails, too. Files like .classpath and .project etc. are not added and hence later not commited. But well, this is the wrong palce to file a bug report.

Solution 5

i use

find . -type f | grep -vP '^.\/.git' |  xargs git add

the grep -vP '^.\/.git' exclude everthing wich start with .git and find get all files include all hidden files.

Share:
53,482
Sergey Kovalev
Author by

Sergey Kovalev

Updated on January 18, 2022

Comments

  • Sergey Kovalev
    Sergey Kovalev over 2 years

    Git seems to always ignore these.

    When I type git add ., dotfiles in GIT_DIR are added, but not from subdirectories. On the other hand, git add subdir/.dotfile won't work.

    I tried git add -f and putting !.* in GIT_DIR/.git/info/exclude.

  • Line
    Line over 10 years
    Which GUI? I'm searching Git tool which shows these files and tried Giggle, Git Cola and gitg and they not showing .files and I don't see any option to enable display them...
  • avgvstvs
    avgvstvs almost 10 years
    @Line from the command prompt, type "git gui" and the prepackaged gui should execute (on Windows.)
  • Line
    Line almost 10 years
    @avgvstvs, thank You, but what if I only use Linux (newest Ubuntu/Fedora)? :)
  • avgvstvs
    avgvstvs almost 10 years
    @Line, the download page forget says they support "git gui" and "gitk." The command might just be git gitk
  • avgvstvs
    avgvstvs almost 10 years
    @Line, verified: sudo apt-get install gitk then in a directory with a .git folder, just type gitk and you've got "git-gui" for Linux.
  • inix
    inix over 9 years
    Your answer help me.Thanks
  • Mona Jalal
    Mona Jalal about 7 years
    what's the fix?
  • Angel O'Sphere
    Angel O'Sphere almost 7 years
    I believe I added them individually without using a wildcard (*). Sorry have no access to a windows machine at the moment.
  • Ferhat
    Ferhat over 6 years
    I have also that problem. Windows 10 64 + git-2.14.2-64 running under Git-Bash git add * adds only some files. Files whom name is starting with . characters not added. So not committed. I didn't find a bug report in github.com/git-for-windows/git/issues
  • user619271
    user619271 over 5 years
    The problem is that when you have many files starting with dot, calling git add for each file takes a really long time.