Excluding files from version control
Let's check up on Bob:
cd ~/jj-tutorial-bob
Done with his part of the assignment, he's already thinking about the submission.
The teacher expects to receive a tarball called submission_alice_bob.tar.gz
.
After a little trial and error, he comes up with the following command to create the tarball:
tar czf submission_alice_bob.tar.gz README.md
Bob wants to spare Alice the hassle of having to figure that out, in case she ends up making the final submission. He decides to add it to the documentation:
echo "
## Submission
Run the following command to create the submission tarball:
~~~sh
tar czf submission_alice_bob.tar.gz [FILE...]
~~~" >> README.md
jj describe -m "Add submission instructions"
Bob is careful to push only clean commits to the remote shared with Alice.
(Be like Bob!)
He double-checks the content of his commit with jj show
:
Commit ID: c4170e871a915f015e97a0e9825d57bcb8dff7fb Change ID: smswwyokuvxtztqmnssvnulswotvmpzn Author : Bob <bob@local> (2025-07-22 21:27:47) Committer: Bob <bob@local> (2025-07-22 21:27:47) Add submission instructions Modified regular file README.md: ... 3 3: The file hello.py contains a script that greets the world. 4 4: It can be executed with the command 'python hello.py'. 5 5: Programming is fun! 6: 7: ## Submission 8: 9: Run the following command to create the submission tarball: 10: 11: ~~~sh 12: tar czf submission_alice_bob.tar.gz [FILE...] 13: ~~~ Added regular file submission_alice_bob.tar.gz: (binary)
Oh no!
It looks like the result of Bob's research was recorded in the commit.
The tarball submission_alice_bob.tar.gz
has no business being tracked in version control.
By default, Jujutsu records every single file in the project into your working copy, which is usually what you want.
But sometimes, you need to tell Jujutsu to ignore certain files and exclude them from being recorded.
For this purpose, Jujutsu reads a special .gitignore
file if it exists in the project.
This file can contain a list of file names, directories, and patterns which describe the set of files that should not be tracked in version control.
To fix the problem, Bob adds a pattern for tarballs to the .gitignore
file:
echo "*.tar.gz" > .gitignore
The star *
symbol is a special glob character which can expand to match any filename, including submission_alice_bob
.
Adding only the precise filename submission_alice_bob.tar.gz
to the .gitignore
file would've worked as well, but the above pattern takes care of any tarball.
Ignoring files globally
Ignoring files globally
Sometimes you might have the same files lying around in several projects that are only intended for your personal use.
In that case, it makes sense to ignore these files globally, not just for a specific project.
It would be a little tedious to add personal files to the .gitignore
of every single project you work on.
One such example is relevant for macOS users:
The Finder application stores hidden files called .DS_Store
in directories opened with it.
These files can end up anywhere and basically never belong in version control.
If you're a macOS user, consider adding .DS_Store
to your global .gitignore
file:
echo ".DS_Store" >> ~/.gitignore
Let's check the commit content again:
Commit ID: ad2a8948eab4ff9829784573d243c0573a0978ce Change ID: smswwyokuvxtztqmnssvnulswotvmpzn Author : Bob <bob@local> (2025-07-22 21:27:47) Committer: Bob <bob@local> (2025-07-22 21:28:48) Add submission instructions Added regular file .gitignore: 1: *.tar.gz Modified regular file README.md: ... 3 3: The file hello.py contains a script that greets the world. 4 4: It can be executed with the command 'python hello.py'. 5 5: Programming is fun! 6: 7: ## Submission 8: 9: Run the following command to create the submission tarball: 10: 11: ~~~sh 12: tar czf submission_alice_bob.tar.gz [FILE...] 13: ~~~ Added regular file submission_alice_bob.tar.gz: (binary)
Hmm... the .gitignore
file has joined the party, but the tarball is still recorded in the commit.
The reason is that Jujutsu only considers .gitignore
for files it hasn't already started tracking.
Since Bob added the .gitignore
after the unwelcome file started being tracked, it had no effect.
Luckily, Jujutsu has a command to make it stop tracking already-tracked files:
jj file untrack submission_alice_bob.tar.gz
The untrack
command only works if the file to untrack is already present in .gitignore
.
Otherwise, Jujutsu would immediately start tracking the file again just after untracking it.
Let's check the commit content one more time:
Commit ID: e583fa6efff0955761e7605b3f49fa9163c9c2fc Change ID: smswwyokuvxtztqmnssvnulswotvmpzn Author : Bob <bob@local> (2025-07-22 21:27:47) Committer: Bob <bob@local> (2025-07-22 21:29:27) Add submission instructions Added regular file .gitignore: 1: *.tar.gz Modified regular file README.md: ... 3 3: The file hello.py contains a script that greets the world. 4 4: It can be executed with the command 'python hello.py'. 5 5: Programming is fun! 6: 7: ## Submission 8: 9: Run the following command to create the submission tarball: 10: 11: ~~~sh 12: tar czf submission_alice_bob.tar.gz [FILE...] 13: ~~~
Yay! This commit looks nice and tidy.