Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore .git folder

I have a php project that uses composer for package management. One of the packages is another project belonging to the same repo. I have a need to commit my entire vendor folder, but I want to ignore the .git folder in the sub-project so that it doesn't get treated like a submodule.

So far I have had no success. Things I've already tried:

vendor/.git

vendor/**/.git/

google search

stack overflow search


Here's what the sub-project folder looks like in GitLab. Instead of the files, it's just some kind of reference.

enter image description here

like image 428
bluemoonballoon Avatar asked Jan 05 '16 18:01

bluemoonballoon


People also ask

How do I ignore a folder in Git?

If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.

Should I put .Git in Gitignore?

Normally yes, . gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something. In those cases you probably don't want to force that on anyone else.

How do I exclude a .Git file?

Use your favorite text editor to open the file called . git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.

Is .Git folder ignored by default?

git folder is ignored by default. All others are deamed potentially important for the source-base unless configured otherwise within the repository or at a global level.


1 Answers

It looks like git automatically ignores .git folders in subfolders of root repository.

(master)[/tmp]  
$ mkdir test_root
(master)[/tmp]  
$ git init test_root
Initialized empty Git repository in /tmp/test_root/.git/
(master)[/tmp]  
$ cd test
test/      test_root/ 
(master)[/tmp]  
$ cd test_root/
(master)[/tmp/test_root]  (master) 
$ ls
(master)[/tmp/test_root]  (master) 
$ git init test_child
Initialized empty Git repository in /tmp/test_root/test_child/.git/
(master)[/tmp/test_root]  (master) 
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
(master)[/tmp/test_root]  (master) 
$ touch test_root_file
(master)[/tmp/test_root]  (master) 
$ cd test_child/
(master)[/tmp/test_root/test_child]  (master) 
$ ls
(master)[/tmp/test_root/test_child]  (master) 
$ touch test_child_file
(master)[/tmp/test_root/test_child]  (master) 
$ cd ..
(master)[/tmp/test_root]  (master) 
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test_child/
    test_root_file

nothing added to commit but untracked files present (use "git add" to track)
(master)[/tmp/test_root]  (master) 
$ git add test_child/test_child_file 
(master)[/tmp/test_root]  (master) 
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   test_child/test_child_file

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test_root_file

(master)[/tmp/test_root]  (master) 
$ cd test_child/
(master)[/tmp/test_root/test_child]  (master) 
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test_child_file

nothing added to commit but untracked files present (use "git add" to track)
(master)[/tmp/test_root/test_child]  (master) 
$ git --version
git version 1.9.1
$ git add test_root_file 
(master)[/tmp/test_root]  (master) 
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   test_child/test_child_file
    new file:   test_root_file

(master)[/tmp/test_root]  (master) 
$ git commit -m'1 commit'
[master (root-commit) 4d4b695] 1 commit
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test_child/test_child_file
 create mode 100644 test_root_file
(master)[/tmp/test_root]  (master) 
$ git show
commit 4d4b69589bf4f471c3c784f95f447d2a40ee6d7d
Author: Evgenii Shchemelev
Date:   Wed Jan 6 09:20:03 2016 +0200

    1 commit

diff --git a/test_child/test_child_file b/test_child/test_child_file
new file mode 100644
index 0000000..e69de29
diff --git a/test_root_file b/test_root_file
new file mode 100644
index 0000000..e69de29
like image 114
Yevgeniy Shchemelev Avatar answered Oct 03 '22 22:10

Yevgeniy Shchemelev