alexkarle.com

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

use-git.7 (3776B) [raw]


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