How to use git between devices?

RMAG news

If I’m working on a feature, on a branch, I struggle to do that while working ‘remotely’.

When I work remotely I don’t mean from the kitchen table, in a wfh style. My use-case is doing a couple of hours on a desktop at home, then maybe continuing on the train with a laptop as I travel to see some friends. Or going away for a few days and doing a couple of hours coding every morning.

I also use git history to keep track of progress, or track down rogue commits. So trying to maintain meaningful (one line) commit messages is important.

Through the years I’ve never found a good way to maintain a meaningful git history, while updating code on different devices. It’s often too impractical to commit fully worked features, because I’m not actually finished yet but have to go off somewhere.

I’ve effectively created a desire line, by committing and pushing whatever I have as a checkpoint so I can continue the work on another device.

For example. I’m adding a new function as part of a feature, at home on a desktop. I don’t quite have time to get it finished before I have to leave for a meeting. But I can use the sixty minute train ride to finish the work, using my laptop.

I’d just commit what’s done with a message of checkpoint. Then twenty minutes later pull changes on the branch from my laptop, and finish it off.

The ideal would be a git log of commits with the checkpoint (or transfer) commits removed, while meaningful commits remain.

But I’m interested to know if anyone else has a better method?

What I’m thinking is somehow automating the following, maybe via an alias function or git hook.

Current state:

$ git log –oneline
9ac99be (HEAD -> feature) meaningful 2
1736b60 checkpoint
5de2fe5 meaningful 1

Move HEAD back to the last meaningful commit, but leaving the code intact:

$ git reset –soft HEAD~2

$ git log –oneline
5de2fe5 (HEAD -> feature) meaningful 1
9679310 (develop) initial commit

$ git status
On branch feature
Changes to be committed:
(use “git restore –staged <file>…” to unstage)
modified: main.go

Now commit the next change:

$ git commit -m ‘meaningful 2’
[feature 6fd925e] meaningful 2

$ git log –oneline
6fd925e (HEAD -> feature) meaningful 2
5de2fe5 meaningful 1
9679310 (develop) initial commit

$ git diff 6fd925e~
diff –git a/main.go b/main.go
index f33752a..8e3863f 100644
a/main.go
+++ b/main.go
@@ -4,4 +4,6 @@ import “fmt”

func main() {
fmt.Println(“meaningful 1”)
+ fmt.Println(“checkpoint”)
+ fmt.Println(“meaningful 2”)
}

Leave a Reply

Your email address will not be published. Required fields are marked *