Search code examples
gitgithubgit-branchgit-pushgit-remote

Can I use two remotes with one local repo and use one of the remotes just to sync desktop and laptop?


I have a local git repo. I push and pull to a remote repo that I share with colleagues and don't want to push unfinished and untested changes. I have a desktop and a laptop computer on which I want to work on the same project and I want them to be in sync. Basically I want to sync unfinished and untested changes just so I can switch from office to home office and just continue on my laptop computer without losing changes and without having to commit trash to the remote I share with others.

  1. Does putting the entire project including git files into the cloud and syncing across devices (desktop and laptop) work? My intuition is that is a bad idea. Which brings me to:

  2. Can I use my private Github account to add as a second remote and commit and push/pull to and fro my two devices (desktop and laptop) and only push/pull to the "main" remote when I am ready to? What would the workflow look like? Would it involve branches? If so, how exactly? Have one "work_in_progress" branch that I just push to my private remote? Can one push a branch to just one remote and not have it influence the other remote?

I tried 1) before which made onedrive create multiple copies of certain files, which I don't want. I want to have a "local" repo that pushes to / pulls from "main" remote but also is in sync across two devices (desktop and laptop).


Solution

  • When you say you don't want to push to the remote repo you share with colleagues, are you saying you would be pushing to the main branch? I agree that this wouldn't be good, since nobody wants trash on the main branch. But I don't see anything wrong with making a branch yourself, and even calling it "my-work-in-progress", and syncing with that branch in that repo from all your computers. This way it wouldn't be messing with the main branch, and a branch named like that would expect to have code that's not working right yet. Then merge from that into the main branch when you're ready. With git, branches are cheap, so make as many as you like. Personally, I would go with this approach.

    As for storing code in your personal repo, you should probably first check with the higher-ups to see if they have a problem keeping official code on a non-official server. If they agree, then I think that would work fine. Your local git project can happily have multiple remotes, if you know how to deal with them. You can pull and push to each one as needed.