Zettelkasten Forum


Feedback request: using Git for zettelkasten notes

I'm wondering if it could be useful to use Git for version controlling my files into the zettelkasten folder. Anymore uses Git for their writing, any feedback to share?

My use cases:

  • know new files created since date d
  • know differences in a file between 2 dates
  • ..

But I think find command and Mac version control are enough for those simple use cases. Maybe Git could be used for more useful things regarding the zettelkasten method...?

Comments

  • When I developed the first version of The Archive, I put my notes under version control with git to see if anything odd happens -- are all reported deletions expected? Was note A overwritten with the contents of note B due to some asynchronous operation?

    As a safeguard, I liked this a lot. Considering that you can automate checking in changes daily at midnight, you can use git diff to calculate how much you wrote each day. Apart from toying around with that, I didn't find any value in keeping a version control system for my notes.

    Author at Zettelkasten.de • https://christiantietze.de/

  • I realize this is an old thread, but I'm reviving it because I search for the same topic---Git. I use git for sure. I plan to use it for as long as I use my Zettelkasten. I'd be happy to help others learn the benefits of it if anyone asks.

  • @adamcross, I would love to discuss this. I learned how to use Git for the Masters program I just completed, and I would love to apply it to my ZK. Other than just setting it up for the folder of notes, is there anything you recommend?

  • edited February 2022

    @Sociopoetic Depends how much you mean by "setting up". You might already be doing the whole thing. I work in Zettlr, which creates the zettelkasten in the form of plain text files. Any app that also creates zettels as text files will also work with it.

    I use Git at the command line, so I'll be thinking and talking here in terms of commands you run.

    For me, syncing is a big deal, and that's going to be one of the main take-aways. I've tried at least one cloud solution already. I tried just putting my Zettelkasten on OneDrive. It didn't work. I was able to open it on one computer, but not on another. I just got a random error I could never get past. However, if for whatever reason the cloud works for you, then maybe you don't need to bother with something like Git. I wish the cloud "just worked" for me. But Git does have other advantages.

    You git init the folder to sort of turn on Git and have it watch the contents of the folder. There might be certain program-specific files you don't want watched. Zettlr creates a file like this, and it doesn't interest me or belong in my repository, so I add that to a .gitignore file. Files listed in .gitignore will be...ignored. I only want it to watch my zettels.

    Every other text file in the directory gets watched for changes. You can do some sophisticated things, but here is a basic worthflow. At any time, if you run git status it will show you what the current changes are. If you want to commit those changes you can do something like git add ./ to add all of the changes. Or you can selectively add just certain ones by using git add [file]. Then git commit -m [commit message] to commit the changes.

    There are at least two really great things about using Git. One is that if you accidentally destroy data it is easy to recover. There are thousands of tutorials out there on using Git, and I won't repeat all that. My main point here is just that you can use it for Zettels, and I do.

    The second wonderful feature is that you can use Git to sync a Zettelkasten among two or more machines. If you create a repository on, for example, Github, then you can keep your Zettelkasten on Github as a private repository. Then you can push your current directory to Github so it's all there. Then you can pull it back down to any other computer with Git installed.

    For me this is a continual process. I write new zettels or change existing ones. When I'm ready to "save", in addition to saving the files, of course, I also do a Git commit on the local directory to commit those changes. Then I push the changes up to Github git push origin master. Later, I also pull the changes down onto my Macbook Air where I keep another copy of my Zettelkasten, and they stay in perfect sync because of Git. git pull origin master.

    Git is some of the most amazing software that people outside of programming mostly don't know exists.

  • I'll add that Git also makes it easy for me to work on my Zettelkasten using either of my two computers simultaneously, even offline and even when they are not currently in a synced state. They don't automatically try to sync without me telling them to, so things stay local until I explicitly tell them sync.

    Things stay pretty uncomplicated so long as you don't modify the same file on both computers and then try to sync them together. But even if you do, then you just have to manually do a git merge. It's maybe more than what a typical person would want to learn, but for the kind of person who would have a Zettelkasten in the first place... anyway, it's not so hard. It's also easy to avoid.

    Plus there are a lot of people in this world who will help you on forums if you ever get stuck with Git.

  • As mentioned in my reply from 2020, I used git as a safeguard to verify no data was lost.

    Since then, I removed the .git history folder again.

    I wouldn't know how to use this, to be honest. The only way I can imagine using git for my ZK is to have daily commits as automatic snapshots, and then squash (combine) daily commits into monthly commits to reduce the history, and then maybe squash (combine) into yearly commits for some kind of history. -- But what then? :)

    I am quite certain I don't want to apply the habits I picked up from programming where 1 commit is like an envelope around a cohesive piece of work, like "implement image drag and drop into notes".

    How do you make commits? (Dealing with merge conflicts etc. is a whole different problem but I'm already stuck at committing :))

    Author at Zettelkasten.de • https://christiantietze.de/

  • edited February 2022

    I'm a programmer by trade, so Git is one of my trade tools. That's why I know how to use it and such. I can totally understand why most people don't know about it and down care. But it's definitely useful for recovering after data loss, and for preventing data loss in the first place.

    @ctietze You are absolutely right that in programming we like a Git commit to encapsulate some semantically meaningful whole, not just an arbitrary assortment of changes. I do not apply that to my Zettelkasten either. I can't see any way to make sense of it either.

    So I just make a commit each day when I'm finished with my work, or sometimes even multiple times per day--at the end of each sitting basically. And I commit all the work I've done since the last sitting. Having set up the project initially as I described above, usually I just run the following commands: git add ./, then git commit -m "add notes and curate" and git push origin master.

    Thus, my Git commits do not represent semantically meaningful chunks of changes, but I'm not worried about that. You don't have to use Git that way. You can just use it like a very robust save/undo system. That's how I'm using it here. Committing is a way of saving the data, and it creates a kind of snapshot of what the ZK looks like at that point in history. If, for some reason, you wanted to go back to that time period you could do that easily---for example, to get the contents of a slip that was deleted accidentally.

    I will emphasize that 70% of the reason why I bother doing all this is to aid with syncing between multiple computers. If I could find some fully acceptable cloud-based solution that does it all automatically, I'd probably use that instead. But I know and I like Git, and it works well for my needs. So I wrote what I wrote wondering if other ZK enthusiasts out there also use Git.

    I'll also mention that there are other tools one could use for the purpose of simply creating backups automatically if that is all one wants. I'd just rely on the cloud to keep my zettelkasten backed up if all I wanted was a backup solution. For me it's important that I can actually work in my ZK on either of my computers, offline if need be, and then sync them back up afterward. Git isn't the only solution for that, but it's one that works for me.

    @ctietze I just read your profile and figure out that you are also a programmer. Forgive me if it sounded like I was explaining things you already know. I was also talking to a general audience of anyone who might happen to read this.

    Post edited by adamcross on
  • @adamcross said:
    I will emphasize that 70% of the reason why I bother doing all this is to aid with syncing between multiple computers. If I could find some fully acceptable cloud-based solution that does it all automatically, I'd probably use that instead.

    TL;DR
    Where syncing two computer is required there are things to look for in a cloud based solution.

    Aside from the ubiquitous local and off-site backup, the only reason for me having my ZK in the cloud is because I have the luxury of more than one Mac. One in the home office and one in the shop. (My office and shop are 50 meters apart.) I'm often working on a zettel in the office, and I'll migrate to the shop. Suddenly ideas will collide, and I append to the zettel I left open on the desktop in the office. The reverse happens when it is lunchtime, and I head back to the house.

    I'd have to constantly be making commits and syncs to make GIT work and still I'd have lots of conflicts to resolve.

    I use DropBox. Primarily for historical reasons. My previous employer (12 years ago) didn't block network access to DropBox. I'm too lazy to switch cloud storage providers. That is my excuse. DropBox syncs quickly. The Archive autosaves and I can leave a zettel in edit mode in the office, go to the shop, and make further edits without conflicts. The problem with DropBox is that when syncing, the modification and creation times are reset. I've not found this to be a problem because I have the creation time in the filename. It sure would have been nice to know this when I started. I'm not sure I'd do anything different though given my laziness.

    Will Simpson
    I must keep doing my best even though I'm a failure. My peak cognition is behind me. One day soon I will read my last book, write my last note, eat my last meal, and kiss my sweetie for the last time.
    kestrelcreek.com

  • @Will Git definitely wouldn't be able to handle the situation you describe---not gracefully anyway. I have not had any luck with cloud solutions before, but I haven't tried using Dropbox. It could work.

    Even if it did work, I'll say that because of reasons I'm not sure how to articulate I would still use Git and version control on my Zettelkasten. I just maybe wouldn't need to use its features for syncing purposes. But I'd still use it.

    I'm going to think about trying Dropbox and see if that works. Thanks for the tip.

  • For what it's worth, I discovered why I was having trouble using OneDrive to sync my two computers and work on my ZK from either one. It's because one computer is a Mac and the other is a Windows machine, and those two systems encode line breaks in text files slightly differently (https://www.oreilly.com/library/view/mac-os-x/0596004605/ch01s06.html). Git is aware of this difference and handles it automagically somehow.

    There might still be a way for me to set up a system as seamless as yours, @Will. But it would certainly be easier if all my computer used the same OS, and that isn't likely to be any time soon. When I'm at my desk, I use my desktop computer, a PC. But when I'm in bed or in the kitchen, etc, I use my Macbook Air, and I love that little laptop. I use it almost exclusively nowadays as a Zettelkasten terminal.

Sign In or Register to comment.