Reputation: 2078
Suppose, I have a centralized git repo at github/bitbucket, and I code either on my laptop or my workstation at the university. What is the most effortless way to sync my current working copy of the code on both of these machines so that I always have the option of picking up where I left off?
I've read the other threads on SO, and they mostly involve commiting to a new branch and pulling/using a usb key/dropbox. But since dropbox might corrupt the git repo, Is there a method, which will allow me to always seamlessly resume where I left off?(Both machines have internet access).
Here are the options I can think of, feel free to add more.
Have a work-in-progress branch on the centralized repo and rebase whenever you want to merge.
Pros:
Most conflicts will be taken care of by git automatically.
Cons:
For each project, have a private repo to sync the work-in-progress branch. Maybe set up vim hooks to automatically commit to that branch
Pros:
Cons:
Create a bundle for each project, sync bundle folder using dropbox
Pros:
Cons:
Store project folder on Dropbox
Pros:
Cons:
Find a way to store multiple repos in a single private repo on bitbucket and have a setup similar to option 2.
I think this might be the best solution, does anyone have suggestions on how I do this?
Upvotes: 1
Views: 358
Reputation: 70275
[YES, It Is This Easy...] The shared location on GitHub will be the 'origin' for all your local development machines. Once you set up origin, your day-to-day, machine-to-machine workflow is essentially:
== machine-1
# edit
$ git commit ...
$ git push origin <branch>
== machine-2
$ git pull origin <branch>
# edit
$ git commit ...
$ git push origin <branch>
== machine-1
...
If you forget 'git pull origin' when you start work on the day's machine, then when you push you may see a conflict that you'll resolve.
If you want the history to be clean, then make a branch for each feature, update frequently on that feature branch as you change machines day-to-day and then, when you merge the feature into master (or where ever) rebase to get a clean history. Note, you'd normally rebase when merging a feature anyway; you'll just have 'extra' day-to-day commits to deal with.
Upvotes: 3
Reputation: 155
You can probably write a script which calls the git commands for you (maybe node or scripting language of your choice). Commands you might want to use (which I use for a workflow similiar to yours) @see how to pull from remote git repository and override the changes in my local repository
Upvotes: 1
Reputation: 2338
I'm in favour of what the other threads suggest: git is capable of doing this perfectly well, so use the facilities it provides. It can be pretty lightweight: do your work on a branch, and commit/push to the central repo when you need to switch machines. If you prefix these commit messages with "squash!", then you can later use git rebase -i --autosquash
to rebase your branch onto its parent (perhaps master
) and those commits will automatically be marked to squash (i.e. disappear) so you won't have any noise. This works best if you're already using a rebase workflow, of course.
Upvotes: 2