Hi programmers,

I work from two computers: a desktop and laptop. I often interrupt my work on one computer and continue on the other, where I don’t have access to uncommitted progress on the first computer. Frustrating!

Potential solution: using git to auto save progress.

I’m posting this to get feedback. Maybe I’m missing something and this is over complicated?

Here is how it could work:

Creating and managing the separate branch

Alias git commands (such as git checkout), such that I am always on a branch called “[branch]-autosave” where [branch] is the branch I intend to be on, and the autosave branch always branches from it. If the branch doesn’t exist, it is always created.

handling commits

Whenever I commit, the auto save branch would be squashed and merged with the underlying branch.

autosave functionality

I use neovim as my editor, but this could work for other editors.

I will write an editor hook that will always pull the latest from the autosave branch before opening a file.

Another hook will always commit and push to origin upon the file being saved from the editor.

This way, when I get on any of my devices, it will sync the changes pushed from the other device automatically.

Please share your thoughts.

  • solrize@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    6 days ago

    I just manually push and it’s fine. Or as the other commenter says, use a single remote machine.

    • Mihies@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      6 days ago

      A remote machine might not be always possible, such as when you develop mobile apps or when you have more than one monitor available. Sadly all options have problems. And (auto) pushing is not an option when you work on a team project where pushing non compilable code is not a welcome option.

        • Mihies@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          6 days ago

          They might work, but then one is bound to be online. Also different computers might have different configurations and that is something to pay attention to as well. Alternative is a synchronisation to source (nextcloud sounds a good fit) but then you might bump to synchronisation conflicts and such. Both ways will produce a lot of traffic unless you redirect creation of build artifacts to a local directory. Which might not be always possible.

    • matcha_addict@lemy.lolOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      6 days ago

      Two issues with manual pushing that I have:

      • you have to remember to push
      • you either get more commits than you need, or you have to do extra work to either clean up or put them in separate branches