Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add newly created specific folder to .gitignore in Git

Tags:

git

gitignore

I had a clean working directory and brought in a clone from a Git repo last night. But now my local server created and contains a stats folder which I want to ignore.

I can't seem to get Git to ignore this folder when I run a git status.

On branch master Your branch is ahead of 'origin/master' by 1 commit.  Changes to be committed:   (use "git reset HEAD <file>..." to unstage)      new file: app_public/views/pages/privacy.php     new file: app_public/views/pages/terms.php     new file: public_html/stats/ctry_usage_200908.png     new file: public_html/stats/daily_usage_200908.png     new file: public_html/stats/dns_cache.db     new file: public_html/stats/hourly_usage_200908.png     new file: public_html/stats/index.html     new file: public_html/stats/usage.png     new file: public_html/stats/usage_200908.html     new file: public_html/stats/webalizer.current     new file: public_html/stats/webalizer.hist  Changed but not updated:     modified: .gitignore 

I added in my .gitignore a few different lines but it still trying to add them:

public_html/stats public_html/stats/** public_html/stats/**/* public_html/stats/* 
like image 866
Lee Avatar asked Aug 26 '09 14:08

Lee


People also ask

Can I add Gitignore after creating repository?

You can both an . idea and a . gitignore file after creating the repo.


2 Answers

Try /public_html/stats/* ?

But since the files in git status reported as to be commited that means you've already added them manually. In which case, of course, it's a bit too late to ignore. You can git rm --cache them (IIRC).

like image 102
Michael Krelin - hacker Avatar answered Oct 01 '22 15:10

Michael Krelin - hacker


For this there are two cases

Case 1: File already added to git repo.

Case 2: File newly created and its status still showing as untracked file when using

git status 

If you have case 1:

STEP 1: Then run

git rm --cached filename  

to remove it from git repo cache

if it is a directory then use

git rm -r --cached  directory_name 

STEP 2: If Case 1 is over then create new file named .gitignore in your git repo

STEP 3: Use following to tell git to ignore / assume file is unchanged

git update-index --assume-unchanged path/to/file.txt 

STEP 4: Now, check status using git status open .gitignore in your editor nano, vim, geany etc... any one, add the path of the file / folder to ignore. If it is a folder then user folder_name/* to ignore all file.

If you still do not understand read the article git ignore file link.

like image 27
Kshitiz Avatar answered Oct 01 '22 15:10

Kshitiz