Browse Learn Clojure Foundations as a Java Developer

Initialize a Clojure Git Repository

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.

Before the First Commit

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.

Initialize the Repository

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.

Use a Clojure-Aware .gitignore

Start 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.

Make the First Commit Reviewable

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.

Commit Runnable Knowledge

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.

Avoid Common First-Commit Mistakes

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.

Knowledge Check

### What should Git capture from a Clojure REPL-driven workflow? - [x] Source files, tests, resources, and commands that reproduce the work - [ ] Every value evaluated in the REPL - [ ] Generated jars and class files from every local run - [ ] Editor cache files > **Explanation:** The REPL is an exploration tool. Git should capture the source truth needed to recreate the behavior. ### Why should `.cpcache/`, `target/`, and `.nrepl-port` usually be ignored? - [x] They are local or generated artifacts rather than durable project source - [ ] Git cannot store hidden files - [ ] Clojure cannot run when ignored files exist - [ ] They replace `src/` and `test/` > **Explanation:** These files can change between machines and runs. Keeping them out of Git makes reviews cleaner. ### What should you inspect before the first commit? - [x] `git diff --cached` or an equivalent staged diff - [ ] Only the output of the REPL - [ ] Only the project name - [ ] The remote branch count > **Explanation:** A staged diff confirms exactly what will become repository history before the commit is created.
Revised on Saturday, May 23, 2026