1

Short question:

  • Is there tricks from git, (or command-line/Git-bash/WSL_on_Windows), such that I will be hosting the git-repo locally, in wherever I prefer, and have only the real files synced two-ways between the local git-repo and a Dropbox folder?

  • Even shorter: is there a way to push from a local repo to a Git remote, and have the files stay "two-way-synced" to a Dropbox folder before and after the push?

At the end of the day, I would like to keep pushing to the remote git-repo as usual. I will push shortly after committing, and would prefer all file-contents from the two sources (the Dropbox folder and the local copy of the Git-repo) to stay synced before and after the commit-push activities. (I am less confident here as this may go against the philosophy of "staging" my works per each commit.)

Clarification: I do not intend to do anything fancy with Git. I prefer to keep working with the same branch, and to pull/push from/to the same Github repo as the remote. In particular, I will need to get things to work on multiple PCs and a Linux machine.

Unsuccessful attempts:

  1. First, I think it is a bad idea to initialize a git-repo inside the ~/Dropbox folder, as it creates clutters and thereby, likely, conflicts.
  2. I have thought about creating a "Selective-sync" through the Dropbox GUI to simply exclude the .git folder. Yet, without such .git folder, it is unclear how to establish the local repo on all computers of mine (I do use multiple Windows PC and one more Linux box).
  3. I am not good at symlink, and have been playing with it a good number of times but failed. If someone were to suggest it, please be precise. Also, I would need it to work across multiple Windows machines and Linux box. I am happy to add more details as long as I get a working demo from you.

Backgrounds

Thankfully, my collaborators has improved from the emailing habit of handing off drafts and work-in-progress through piles of zip-files. Nowadays, they are happy with a shared Dropbox folder. Yet, they haven't started to care too much about version control. Quotes from them: "Git on the command-line? It is a joke?" lol.

On the other hand, I have been happy with pushing to Github as my remote repo, and have been doing so for a good number of years. I am used to my git commands, and have devised the following alias settings to do so quickly.

alias ga='git add -A'
alias gs='git status'
alias gc='git commit -m'
alias gp='git push'
alias gpp='git pull'

I am looking for a way to use Git(Github) and Dropbox in harmony. And I am aware of the following knowledge:

Among the three unsuccessful attempts on my end, I am inclined to believe some symlink command (or complicated scripts) will do the trick. Looking forward to further instruction from the community. I am tagging as many vision control

llinfeng
  • 1,316
  • 1
  • 15
  • 39
  • 4
    Seriously, dropbox is not an acceptable, professional way of working on software sources. Educate them. If they're afraid of the command line, make them use a git UI like SourceTree. – JB Nizet Dec 09 '18 at 22:49
  • Hi @JBNizet. I totally agree with you. Yet, I am the primary programmer of the team, and others are in charge of other aspects. The most sophisticated tasks that are left should be editing `*.tex` documents, which people have been super fluent with. I found [this `git `command](https://git-scm.com/docs/git-worktree) of potential value. As commented [here](https://discuss.ropensci.org/t/peace-between-git-and-dropbox-with-git-worktree/289), it is good for virtually "separating" the super-large `~/.git` folder from files in other branches that are stored on Dropbox. – llinfeng Dec 10 '18 at 03:30

1 Answers1

1

Tentative attempt using git-worktree?

Inspired by noamross's post, the following quote looks applicable to my situation

With git worktree, you have one or more “linked working trees” (linked directories) connected to the “main working tree” (main directory). Importantly, linked directories do not have .git folders. Instead, they have .git files which point them to the main directory. This means they are much less trouble to sync with Dropbox.

The steps appear to be super relevant, and I feel like experimenting the following: * Initialize the repo somewhere else; * As suggested in the original post, issue the command git worktree add -b dropbox ~/Dropbox/project-repo-dropbox to create the other branch on Dropbox.

Remaining documentation for the git-worktree method (missing for now)

  1. How to replicate the git worktree setting on another Windows/Linux machine?
  2. Good reference on "branching in Git". I have personally not used branches a lot, and will need to update this post with a complete workflow.
  3. Well, a simple answer whether the proposed recipe works or not. (Didn't have the time to try it out yet.)

Please advise if you have better ideas :)

llinfeng
  • 1,316
  • 1
  • 15
  • 39
  • This seems likely to work, to some extent. It means that you can let Dropbox update the added work-tree whenever and however Dropbox likes, and then manually use the added work-tree to update the repository whenever *you* choose. There's a fair bit of manual work involved and, for any use of `git worktree add`, you should be sure you have at least Git 2.15 if possible. – torek Dec 10 '18 at 04:34
  • @torek, thank you for the kind comment. Will I get into trouble if I were to repeat the same `git worktree add` command on multiple Windows PC? After all, there is only one Dropbox destination that I would like to write to. – llinfeng Dec 10 '18 at 04:43
  • Each Windows box needs to have its own local repository. If you're using a shared (network) drive for the local Git repository—I don't know whether this works; I avoid Windows—then each added work-tree would also have to be on its own branch, as there's a `git worktree add` constraint that requires every added work-tree to use a different branch from every other existing work-tree. – torek Dec 10 '18 at 05:46
  • I see the challenge here: although I am more than happy to keep a "real" local copy of the Git repository (somewhere outside Dropbox), chances are that I shall end up creating new branches for each of my Windows/Linux "box"? [Notes on Windows with Git ==> they are working just fine] [Clarification: I am more than happy to restrain from using any other "Network Drive" of any sort. Local copies are physical and *real* :)] – llinfeng Dec 10 '18 at 15:40
  • OK, well, as far as (each) Git is concerned, the local repository (`.git` directory and contents) are to be touched only by Git, and only on *your* machine, which is the center of the universe. :-) So each Windows system's Git is independent, and you're fine there. The only remaining issue will be whether Dropbox fiddling with each system's work-tree functions properly: Git records `stat` data to know if some user (including perhaps Dropbox as a user) has been fussing with the work-tree content, so ... [continued] – torek Dec 10 '18 at 16:15
  • ... so if Dropbox changes a work-tree file, it should change it the same way a user would, making the file's time-stamps increase. If Dropbox tries to keep the time-stamps static, Git could miss a work-tree change (Git will see it if the file's reported `stat` data change, so if the file changes *size* Git will see it). – torek Dec 10 '18 at 16:17
  • I totally agree with your comment that the local repository is the center of the universe :). However, I find it challenging to "think through" establishing the same "Dropbox branch" at exactly the same Dropbox location from "variables universes" ==> after setting up `git worktree` with the tag `-b` to create a new branch on Machine A, how am I going to reproduce the same settings on Machine B? By taking away the flag `-b`? – llinfeng Dec 10 '18 at 21:15
  • Have the systems that *do* have Git, communicate with each other via Git protocols, not Dropbox. That is, use push/fetch to go from Git-enabled system to Git-enabled system. – torek Dec 10 '18 at 22:58
  • I do intend to host local Git repos on 2 Windows machines and 1 Linux machine. Given the current implementation of `git worktree`, am I restricted to keep all the Git-related activities on one machine only? – llinfeng Dec 11 '18 at 03:07
  • No, but you'll want to have the Git-enabled machines use Git protocols and non-Dropbox worktrees to talk to each other. Pick one machine to use to talk to non-Git Dropbox-only systems, add the one worktree there, and use that one machine to do that communication. Otherwise you'll have a maintenance nightmare ("who has the latest?"). – torek Dec 11 '18 at 03:29
  • Thank you for raising the concern for "who has the latest"? I should probably restrict myself to working with one local Git repo at a time. Any advise on the specific command to use when I **need** to "move" from one machine to another? [Comment on THE QUESTION: I tend to be dealing with different portions of the project on different machines. Say, I was scarping using the Linux machine, and saving pickles every-other-hour. These hourly-dumped pickles are *ignored*, and only the non-duplicates are pushed. These aggregated pickles are used for analysis elsewhere. ... [continued] – llinfeng Dec 11 '18 at 16:45
  • ... [continued] By "elsewhere", it is usually the Windows laptop that I tend to carry around with me. I will continue from whatever has been scraped so far, and update the analysis in Jupyter Notebook. At the end of the day, I should be writing to different sub-directories from different machines. This worked for me.] I am by far not a "good" programmer, and there are many practices that I need to standardize. @torek, thanks a lot for your patience and guidance. For the particular project that I would **have** to work with Dropbox people, I shall follow your advise and ... [continued] – llinfeng Dec 11 '18 at 16:50
  • ... and keep one local Git repo on a specific machine. After all, it is a good idea to separate projects from each other by distinguishing the work-environment "physically" :) I was asking about the question about "migrating" from one machine to the other, as the manufacturer for my laptop will finally send me the "fixed laptop" after months of debugging. I wanted to setup such Dropbox-branched-from-Git thing on my laptop, both the current loaner one and the one that I bought originally. – llinfeng Dec 11 '18 at 16:53
  • Ah ... well, you're getting well past scenarios I've imagined. I'm not sure I have any good advice for these cases... – torek Dec 11 '18 at 16:58
  • Those were previous "good" cases where well-disciplined asynchronous pushing and pulling from **totally separate directories** did no more than minimum harm. I do take your advise on keeping the scenarios as simple as possible for `git worktree`. Will post a more specific question about establishing the "worktree" for Dropbox across multiple machines. Thanks a lot for walking me through the logics and proper usages @torek :) – llinfeng Dec 11 '18 at 20:50