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.
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.
Unfortunately, git doesn't support branch-specific . gitignore files or directives. Using different .
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 .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With