onmyway133 / blog

🍁 What you don't know is what you haven't learned
https://onmyway133.com/
MIT License
679 stars 33 forks source link

How to create user gitignore #967

Open onmyway133 opened 9 months ago

onmyway133 commented 9 months ago

Git is a helpful tool for managing code and projects, but sometimes you want to ignore certain files or folders only on your computer without affecting everyone else. That's where the .user_gitignore file comes in. It allows you to create personalized ignore rules for your local Git setup without changing the global project settings.

gitignore

Before we get into .user_gitignore, let's quickly go over what a regular .gitignore file does. It's a file where you list files and folders you want Git to ignore when tracking changes. This helps keep your project clean by excluding unnecessary files like logs or compiled code. But remember, a regular .gitignore affects the whole project.

The .user_gitignore file lets you create special ignore rules that only apply to your local setup. Here's how to use it:

Create the .user_gitignore file:

Go to your project's main folder using your command line or Git program. Make a new file called .user_gitignore inside the .git directory (if it doesn't exist, it should be in your project's root). The name is arbitrary, you can name it however you want

cd path/to/your/project
touch .git/.user_gitignore

Add your rules to .user_gitignore:

Open .user_gitignore with a text editor. Put the names of files or folders you want to ignore, just like you would in a regular .gitignore file.

.git/.user_gitignore

# .git/.user_gitignore

# Ignore temporary files
*.tmp

# Ignore personal config files
config/personal.ini

.node-version

Configuring Git to Use .user_gitignore

After creating .user_gitignore and adding your custom rules, you need to tell Git to use it for your local settings. Run this command:

git config core.excludesfile .git/.user_gitignore

This command makes Git follow your .user_gitignore rules alongside the global and project-specific .gitignore files.