Apply everyday Git commands to Clojure work by staging source changes deliberately, reviewing namespace diffs, keeping generated artifacts out, and syncing branches safely.
Most Git commands are the same in Clojure as in Java. The difference is what you pay attention to in the diff. Clojure changes often alter data shapes, namespace dependencies, tests, and small pure functions rather than large class files. Your Git workflow should make those changes easy to review.
Use this loop when editing Clojure code:
1git status --short
2git diff
3git add src/order_service/pricing.clj test/order_service/pricing_test.clj
4git diff --cached
5git commit -m "Clarify pricing calculation"
The critical step is git diff --cached. It lets you verify that the commit contains source changes, test changes, and no generated artifacts before you create history.
| Command | Clojure-specific habit |
|---|---|
git status --short |
Check for generated files such as target/, .cpcache/, logs, or REPL artifacts. |
git diff |
Read namespace imports, data shape changes, and test expectations carefully. |
git add <path> |
Stage related source and test files together instead of blindly adding everything. |
git restore --staged <path> |
Unstage accidental artifacts without deleting the working copy. |
git commit -m "..." |
Write messages around behavior, not line-count movement. |
git log --oneline -- <path> |
Understand why a namespace or test changed before rewriting it. |
Avoid using git add . as a reflex in Clojure projects with active REPLs or build tools. It is easy to stage local artifacts when a project has generated files.
Modern Git supports git switch; older workflows may still use git checkout.
1git switch -c feature/pricing-rules
2git fetch origin
3git rebase origin/main
4git push -u origin feature/pricing-rules
For a shared branch policy, follow the team’s rule. The important Clojure habit is to sync before review so reviewers are not sorting through stale namespace conflicts and outdated test failures.
| Task | Safer command pattern |
|---|---|
| Create a branch | git switch -c feature/name |
| Update branch from remote | git fetch origin then rebase or merge according to team policy |
| See recent work | git log --oneline --decorate --graph -20 |
| See one file’s history | git log --follow -- path/to/file.clj |
| Compare with main | git diff origin/main...HEAD |
Java diffs often focus on class methods, visibility, and object boundaries. Clojure diffs often need a different review lens.
| Diff area | What to check |
|---|---|
ns form |
New dependencies, aliases, circular require risk, and unused imports. |
| Function signature | Whether callers and tests still match the data shape. |
| Data literals | Keyword names, nested map shape, defaults, and missing-case behavior. |
| Tests | Whether expectations describe behavior rather than implementation trivia. |
| Build files | Whether dependency or classpath changes affect REPL, test, and production commands. |
This is why small commits matter. A commit that changes data shape, namespace wiring, and packaging all at once is hard to review even if the line count is small.
Use non-destructive commands first.
| Goal | Command |
|---|---|
| Unstage a file | git restore --staged path/to/file.clj |
| See what changed in one file | git diff -- path/to/file.clj |
| Discard local edits in one file only | git restore path/to/file.clj |
| Keep work but move it off the branch temporarily | git stash push -m "message" |
| Inspect a previous version | git show HEAD~1:path/to/file.clj |
Be careful with destructive commands such as hard resets. They can erase valuable REPL-to-source work if you have not committed or stashed it.
Before committing Clojure work:
git diff --cached.