MaruOpsInfrastructure and AI notes

About (Korean)Contact (Korean)

[Git and GitOps 13] Review gitignore, Line Endings, LFS and Secrets

Laptop keyboard and trackpad

Reference photo · Laptop keyboard and trackpad · Photo: Scott Webb scottwebb / Source / CC0 · Resized for listings; illustrative photo, not the tested environment

Decide which files belong in history before caches, build artifacts and accidental data make a repository difficult to review. Record line-ending rules if the project moves between Windows and Linux. Treat large assets and secrets as separate storage and access decisions.

This article is hosted in the gitops-demo repository. If you already have .gitignore and .gitattributes, do not delete the existing entries, but merge the required rules. Rewriting large amounts of history is not included in this part’s basic exercises.

Git · GitOps All Series · 13 / 24

On this page

Decide which files you do not want to track

Here are the starting rules for the Python example: Excluding the environment file, which may contain actual secret values, the configuration items to be shared are described as .env.example, which has no secret value.

__pycache__/
.venv/
dist/
.env
*.agekey
git status --ignored --short
git check-ignore -v .env

check-ignore -v is used to check which rule excluded a file. .gitignore is the processing rule for file not yet tracked. Already committed .env will not be automatically removed from the past history and current tracking status later.

# Only if .env was already tracked; leaves the working file in place.
git rm --cached -- .env
git add .gitignore
git diff --staged
git commit -m "Stop tracking local environment settings"

This command does not clear secret values from history. If the key is included, check whether it has been made public and proceed with disposal/reissue first. You should also check whether the same values ​​remain in the search cache, fork, CI logs, and deployment environment.

Line break policy is shared through .gitattributes

* text=auto
*.py text eol=lf
*.sh text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.ps1 text eol=crlf

LF and CRLF are ways to express the end of a line. CR characters left in a shell script may cause Linux to fail to resolve the execution path or options. By placing rules for each file type in the repository, you can reduce situations where you only rely on each developer’s global settings.

When adding policies to an existing project, clean the working tree and normalize it in a separate branch. It does not mix with functional changes.

git switch -c chore/line-endings
git add .gitattributes
git add --renormalize .
git diff --staged --stat
git diff --staged --check
# Inspect the full diff before committing.

If the entire file appears to have changed, check to see if it’s the line break conversion you expected. Do not commit without review or batch change core.autocrlf values ​​for all environments.

Large binaries try different storage paths

Git LFS records small pointers inside Git and keeps the actual large files in an LFS repository. This may be useful for image sources or necessary binary assets, but it may not be appropriate to unconditionally move all build results and backups to LFS. In some cases, it is more appropriate to use an artifact repository for deployment files and a container registry for images.

# Requires Git LFS installed on the client and support on the server.
git lfs install
git lfs track "*.psd"
git add .gitattributes
git lfs ls-files

This is not a command that automatically removes existing large commits. Also check the server’s LFS support, capacity policy, and backup destination. Even if the clone succeeds, if you don’t receive an LFS object, you may only have a pointer instead of an actual file.

For the operation of the rules, refer to gitignore, gitattributes, and for the structure of large objects, refer to Git LFS Official Guide. What you leave in the repository is determined by the purpose of storage, along with the file size.

Previous · [Git and GitOps 12] Use Tags and Releases to Identify a Deployment · Next · [Git and GitOps 14] Build a Local Git Server with Bare Repositories and SSH · Series list and example files