Start a Clojure repository with a clean first commit, a Clojure-aware `.gitignore`, reproducible commands, and clear source-of-truth boundaries for REPL-driven work.
Initializing Git for a Clojure project is not hard. The part worth doing carefully is deciding what the repository should treat as source truth. Clojure encourages REPL-driven exploration, generated build outputs, editor integrations, and local caches. Git should capture the source files, tests, resources, and documentation that recreate the work, not every artifact your local workflow produces.
Do these checks before git add .:
| Check | Why it matters for Clojure |
|---|---|
src/, test/, and resources/ are in place |
Reviewers can predict where namespaces, tests, and classpath resources live. |
| Build command is documented | Java teammates should not guess whether to use clojure, lein, Maven, or Gradle. |
.gitignore exists |
Generated classes, jars, caches, and REPL history should not pollute reviews. |
| Formatting rule is known | Parentheses-heavy diffs are much easier to review when whitespace is consistent. |
| Local secrets are excluded | REPL convenience files must not become committed credentials. |
From the project root:
1git init
2git status --short
If the project already came from a template, inspect the generated files before committing. Do not trust a template to know your team’s build tool, editor policy, or secret-handling rules.
.gitignoreStart with project-specific entries and keep personal editor preferences either in a global Git ignore file or in team-approved project entries.
# Clojure and JVM build outputs
/target/
/classes/
/.cpcache/
/.nrepl-port
/.lein-repl-history
# Tooling and local runtime artifacts
*.class
*.jar
*.log
*.tmp
# OS/editor noise
.DS_Store
/.idea/
/*.iml
/.vscode/
Treat this as a starting point, not a universal rule. For example, some teams commit .vscode/settings.json to standardize Calva settings, while others keep all editor files local. The policy matters more than the default.
Stage deliberately, then inspect before committing:
1git status --short
2git add deps.edn src test resources README.md .gitignore
3git diff --cached --stat
4git diff --cached
5git commit -m "Initialize Clojure project"
For a Leiningen project, replace deps.edn with project.clj. For a Maven or Gradle host project, include the owning build file and any Clojure source roots that the build actually uses.
A Java engineer joining the repository should be able to answer these questions from committed files:
| Question | Where to document it |
|---|---|
| How do I start a REPL? | README.md, Makefile, bb.edn, or build-tool docs |
| How do I run tests? | README.md and CI config |
| Which build tool owns dependencies? | deps.edn, project.clj, pom.xml, build.gradle, or explicit docs |
| Which files are dev-only? | dev/ conventions and .gitignore |
| Which commands CI runs | CI workflow file or repository script |
The first commit should not just contain files. It should teach the next developer how to reproduce your local success.
| Mistake | Better habit |
|---|---|
Committing target/ or generated jars |
Commit source and build instructions, not generated output. |
Committing only src/ without tests |
Include at least a smoke test or test command early. |
| Hiding the build command in memory | Document the command before the team needs it. |
| Committing local REPL state | Keep source files as truth; REPL state is temporary. |
| Mixing unrelated setup experiments | Make the initial commit small, then commit follow-up choices separately. |