2

I'd like to use VC for development projects, however what I see in the various types (Git, SVN, Mercurial...) doesn't seem to suit what I'd like to accomplish.

What I'd like to do is have the code repositories stored on an external device (such as thumb drive or SD card), not only for version control, but also as a backup in case my local hard drive crashes.

After reading some tutorials on the various VC packages, I'm having some difficulty understanding how that could be accomplished. Most of what I see is the repository has to be initialized in the root directory of the project's directory structure, and that's not where I'd like the repositories to be stored.

It seems to me this creates duplicates of code...
Or am I just missing something ?
Can this be accomplished ?

Any help understanding this is greatly appreciated !

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What do you mean by "project's directory structure"? Do you mean where your IDE keeps the current version of source? The repository can be on a different drive, and even on a different machine across a network. – Darius X. Aug 19 '15 at 19:02
  • Yes, Darius, that's what I mean. And thank you for replying so quickly. I'm just lacking understanding on how to get the repositories stored on a thumb drive or sd card, and only have the directory structure on my hard drive as the 'local check-out' copy. – Gregory R. Pace Aug 19 '15 at 19:16
  • I may very well be missing something in the tutorials that allows one to specify where the repository is actually stored. – Gregory R. Pace Aug 19 '15 at 19:24
  • To help clear thing up a bit, reading a tutorial on Mercurial (http://hginit.com/01.html), it is explained to go to the root directory of the project and initialize the repository (you type hg init... if you look closely, you’ll see that there’s a new directory there, named .hg... That’s the repository!). That's *not* where I'd like the repository to be stored. How does one specify where the repository is stored ?? With what is explained there, if your hard drive crashes, then your repository is gone, too !! – Gregory R. Pace Aug 19 '15 at 19:51
  • I'm not familiar with mercurial, but this lionk speaks to a central repository: http://hginit.com/02.html Also, thread has some info: http://stackoverflow.com/questions/2963040/how-to-clone-repository-to-a-remote-server-repository-with-mercurial – Darius X. Aug 19 '15 at 20:12
  • Thank you, Darius. I did read page 2 of the tutorial... "All you have to do is make a repository with hg init and then serve it on the web with hg serve". Key words here are 'serve it on the web'... I also looked at the 2nd link you provided... Not appropriate for 'singleton' development. – Gregory R. Pace Aug 19 '15 at 20:21
  • I have not used Mercurial, but it is quite typical to run the source-control program on your machine and allow it to "talk" to your IDE via some port. This is not much different from having it run on a different machine and be accessed via the web. Instead, you're running it on your "localhost" so to speak. – Darius X. Aug 19 '15 at 20:26

3 Answers3

1

Since Git is decentralized, you can have:

  • a local repo on your disk where your sources are
  • a bare repo on your thumb drive, where you are pushing your sources to, for backup

That is:

cd /path/to/myproject
git init .
git add -A .
git commit -m "my sources"

Then

cd /path/to/thumdrive
git init --bare myproject.git

Finally

cd /path/to/myproject
git remote add origin /path/to/thumbive/myproject.git
git push -u origin master
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you, VonC. I will absolutely try that. I was looking at Mercurial, but if Git will do it, then so be it. Thanks, again ! – Gregory R. Pace Aug 19 '15 at 20:27
  • @GregoryR.Pace no problem. The notion of "bare repo" is important here. – VonC Aug 19 '15 at 20:28
  • It appears your instructions did get the repository on the secondary device. Now... Just figuring how to update it with the Geany editor. Thanks again. BTW... What exactly is 'bare repo'? – Gregory R. Pace Aug 19 '15 at 21:00
  • @GregoryR.Pace See http://stackoverflow.com/a/26687327/6309 and http://htmlpreview.github.io/?https://github.com/sitaramc/sitaramc.github.com/blob/dce410b2a2804723676db9cabd7bb506b6d9ba05/concepts/bare.html – VonC Aug 19 '15 at 21:05
  • Thanks to all of you generous folks that have helped me understand version control. I've chosen Git, as it appears to be the most used, and coupled with GitEye, I think I like it. – Gregory R. Pace Aug 20 '15 at 22:48
  • @GregoryR.Pace Great! http://stackoverflow.com/help/accepted-answer is appreciated. – VonC Aug 21 '15 at 05:22
1

It seems to me this creates duplicates of code...

No. Repository, generally, isn't "copy of your code" - it's database, which contain your code and additional metadata. I see nothing bad to have two repositories in different places

The above note applicable only for DVCS (Mercurial, Git, Bazaar...), not for CVCS like Subversion, where all and any repository will be remote and .svn dir contain only some metadata (thus - you can have single SVN-repo on external drive)

Conclusion:

  • In case of Mercurial you can't move local repository (.hg) outside the root of Working Dir ("project" in your terms), but can have additional repository on external drive
  • In case of Git, it addition to VonC answer, you can use --separate-git-dir option for git init
  • In case of SVN, you must to have repository outside your Working Copy in any other location
Community
  • 1
  • 1
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
1

You seem to be confusing the concepts and different purposes of repository on the one hand and backup on the other hand.

A repository is not primarily meant to keep a backup. Its main purpose is revision control and history of your source. The version control system I know keep their history data usually relative to the root of the project itself - maybe it can be configured otherwise, but defaults are defaults for good reason usually. However you can easily clone such repository so that another copy of the complete history (or optionally also only partial history) exists on another drive or machine. This mechanism can be abused as backup.

A backup generally is an additional copy of your data (which might be your repository) on another independent medium, preferentially even in another building. This allows restoration of the complete state of your (important) data - which usually for your workplace computer includes the repository along with the working dir state of your repository.

planetmaker
  • 5,884
  • 3
  • 28
  • 37