Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore only on local

I would like to know how to gitignore files but only on local, without pushing it (because the other people working on the project should not get this update of gitignore of files I added there.

To be simple, after a git status I only have :

modified:   .gitignore 

because I added my files to ignore to my gitignore but well now I want the line above gone without pushing it.

like image 213
Max Avatar asked Mar 15 '18 16:03

Max


People also ask

Is it possible to have a local Gitignore?

gitignore ignores files locally, but it is intended to be committed to the repository and shared with other contributors and users. You can set a global . gitignore , but then all your repositories would share those settings.

Is Gitignore specific to a branch?

Unfortunately, git doesn't support branch-specific . gitignore files or directives. Using different .

Does Gitignore need to be in every folder?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .


2 Answers

For local ignores you should use the .git/info/exclude file, not .gitignore:

Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow) should go into the $GIT_DIR/info/exclude file.

The two files accept the same format.

like image 60
Chris Avatar answered Oct 03 '22 00:10

Chris


Gitignore file should be committed because in most cases what you ignore would be ignored by other developers in the team too.

But if you absolutely need to exclude it from being tracked for local changes, you could do the following:

git update-index --assume-unchanged .gitignore

This will make it "disappear" from the modified list. Though if someone else changes it, you will not get the changes on pulling. You'll then need to do the below to bring it back to tracked list and do a pull again:

git update-index --no-assume-unchanged .gitignore

like image 26
Vasan Avatar answered Oct 03 '22 00:10

Vasan