1

I have a private git repo which is similar to a dotfiles repo that I use to track shell history across my servers and machines. I do this to have a permanent record of shell incantations that I can refer back to when I encounter a situation in which I vaguely recall knowing how to do something but don't remember the specific command.

For the past few years I have been manually copying shell history files into this repository of mine, but I have lately come to realize that there should be an easier way to do this. I'm usually pretty good about remembering to preserve the history from an environment before decommissioning it, but the repetitiveness of the process has gotten to be a little grating.

The main limitation is that symlinks are not followed by git. Git will simply record the target location of a symlink if you check in a symlink. What I'd like to do, conceptually, set it up so that it would follow the link: that way, I can simply set up my shell history on on multiple machines, check in the "link" to my shell history files, and then I'd like to be able to simply run git diff there to view and commit any new changes from that point on, without having to manually enter in the file associations again.

If there isn't an easy way to do this, I was thinking maybe a git hook could help, but I don't really know of any client hooks that can run prior to attempting a commit...

I'd like to also mention one behavior which is interesting, with Git on windows it actually does treat symlinks as copies as far as I know. So this should kind of work out of the box on windows. The question is how to trick Linux/macOS on a per-repo basis to do this.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • 1
    Just do the symlink into the other way. Link your `~/.bash_history` to your git file. `ln -s repo/bash_history ~/.bash_history` – Ôrel Jan 06 '20 at 01:15
  • @Ôrel thanks! I think you're right. That should be a workable solution! I was reading another SO question and the same thing was suggested! Please put that in an answer and I will accept! – Steven Lu Jan 06 '20 at 01:15

1 Answers1

1

Just do the symlink into the other way. Link your ~/.bash_history to your git file.

ln -s repo/bash_history ~/.bash_history

I have a script to link all my dot file to a system https://github.com/utix/dotfiles/blob/master/%2Bbin/doconf

Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • Nice. I actually already do this with all my other dotfiles too. It just feels a little "risky" because now your dotfiles rely on the git repo staying in the same location. But it's really not bad. Also see https://stackoverflow.com/a/5787312/340947 for a related discussion :) – Steven Lu Jan 06 '20 at 01:24