alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

use-git.txt (3582B) [raw]


      1 # Non-standard uses for `git(1)`
      2 
      3 _Published: November 7, 2021_
      4 
      5 In this post, I'm not going to teach you how to use
      6 [`git(1)`](https://git-scm.org).  Instead, I wanted to write a
      7 quick post to encourage you to use git for non-conventional use
      8 cases (i.e. things other than source code).
      9 
     10 If perchance you're not familiar with git, there's a ton of good
     11 documentation out there.  I'd recommend starting with the official
     12 and free [Pro Git](https://git-scm.com/book/en/v2). Also, as a PSA,
     13 just know that git stores whole snapshots and NOT diffs.
     14 
     15 ## Background
     16 
     17 Git is a distributed version control system, and this is a
     18 beautiful thing.  I feel it's often lost on us, given that we use
     19 it most frequently on centralized forges for team collaboration
     20 (GitHub, GitLab, etc).
     21 
     22 Git being distributed means you can:
     23 
     24 1. Use it offline (your copy is "first class")
     25 2. Mirror it to as many places as you want
     26 
     27 In other words, git can be used without any dependence on a third-
     28 party service or company and with complete ownership of private
     29 data.  Forges (and I recommend [https://sourcehut.org]) are a great
     30 place to backup your code and collaborate, but you don't have to
     31 use a forge to use git as a futureproof way to do what it does
     32 best: version your files.
     33 
     34 ## Story Time
     35 
     36 When I started my first job in tech, I found that it was a good
     37 habit to take personal notes.  It was incredibly useful to quickly
     38 reference obscure CLI commands or system knowledge gained from
     39 pairing.  These were things that were too small or personal to make
     40 it into standard documentation but invaluable to have on hand.
     41 
     42 My first solution was shoving them all into a directory called
     43 ~/notes as plaintext files.  They were easy to write and reference,
     44 and it was simple to back them up by copying the directory to
     45 another drive nightly.
     46 
     47 Over time, the `cp -a` trick broke down:
     48 
     49 - Files deleted in the source prevailed in the backup
     50 - Changes more than a day old were lost!
     51 
     52 Around the same time, I started getting more familiar with git, and
     53 it finally occurred to me: I could use git and still keep these
     54 notes private!
     55 
     56 Git can clone/push/pull across filesystems, so in the matter of
     57 minutes I solved both of my issues with just:
     58 
     59 	# Set up the backup mirror
     60 	$ git init --bare /backup/drive/notes.git
     61 	
     62 	# Put it to use!
     63 	$ cd ~/notes
     64 	$ git init && git add . && git commit -m "import"
     65 	$ git remote add origin /backup/drive/notes.git
     66 	$ git push -u origin main
     67 
     68 If you don't have a backup drive mounted, it's equally good (or
     69 better) to make the remote a repo accessed over SSH:
     70 
     71 	# On the remote host
     72 	user@example.com~$ git init --bare ~/notes.git
     73 	
     74 	# On the local host
     75 	$ git remote add origin user@example.com:notes.git
     76 
     77 ## Going Further
     78 
     79 These days, I shudder at the thought of any important plaintext on
     80 my system that's not version-controlled somewhere. Too many hours
     81 are spent writing these little files, and it's so easy to version
     82 them, why risk losing any of that history?
     83 
     84 Aside from my private notes, I version:
     85 
     86 - System config files from /etc
     87 - Personal config files (dotfiles)
     88 - My passwords (via [`pass(1)`](https://passwordstore.org))
     89 - A small set of personal patches for FOSS projects I have yet to
     90   polish and upstream (a-la ports-system)
     91 - My resume (admittedly still a DOCX from college, but versioning
     92   has really helped)
     93 
     94 In conclusion, my advice to anyone writing anything of importance:
     95 just use `git(1)`!
     96 
     97 ## See Also
     98 
     99 - [Commits are snapshots, not diffs](https://github.blog/2020-12-17-commits-are-snapshots-not-diffs/),
    100    by Derrick Stolee
    101 
    102 [Back to blog](/blog)