this post was submitted on 25 Oct 2024
25 points (96.3% liked)

Programming

17424 readers
82 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] NegativeLookBehind@lemmy.world 27 points 3 weeks ago (9 children)

Write code on a machine you can remote into from each computer? Less commits, possibly less reverts, less chance of forgetting to git pull after switching machines…idk.

[–] matcha_addict@lemy.lol 1 points 3 weeks ago (3 children)

I have considered this approach, but there are several things I had issues with.

  • there is still a degree of latency. It's not a deal breaker, but it is annoying
  • clipboard programs don't work. They copy to the remote host's clipboard. I bet there's a solution to this, but I couldn't find it from spending a limited time looking into it.
  • in the rare case the host is unreachable, I am kinda screwed. Not a deal breaker since its rare, but the host has to be always on, whether the git solution only requires it to be on when it syncs

To address the issues you brought up:

  • less commits: this would be resolved by squashing every time I make a commit. The auto save commits will be wiped. If I really hated commits, I could just amend instead of commit, but I rather have the history.
  • forgetting to git pull: the hooks I talked about will take care of that. I won't have to ever worry about forgetting anymore.
[–] Strykker@programming.dev 0 points 2 weeks ago (1 children)

Your git solution still has all of these issues, as you need the git server to be alive, for number 3 use something like rsync so you keep a local copy that is backed up if you are concerned about the file share being offline.

[–] matcha_addict@lemy.lol 1 points 2 weeks ago* (last edited 2 weeks ago)

I don't need the client computers to be alive, only the central server (which could be github.com for example, so not even a server I manage).

load more comments (1 replies)
load more comments (6 replies)