18

I have exhaustively searched for answers to my question here and on Google. I have found some great resources and learning tools for understanding Git and what it does, but I need to get some clarification, and assistance.

What I am doing is working on a side-project for work both at my office and at home. (I'm migrating C# code to Java to help me learn both languages.)

The setup:

  • Environment: Windows 7 (VS 2008 is on an XP virtual machine)
  • Git: msysgit 1.7.4
  • IDEs: VS 2008 and Eclipse
  • Git plugins:
    • Eclipse: I am using EGit.
    • VS 2008: I plan on using one mentioned here on SO, Git Extensions
  • Git repository: Located in \Repo on the USB stick - right now it just has a portion of the Java code as I fumble my way through learning Git.
  • C# code in a Virtual Machine with VS 2008 that gets copied out of the VM to the USB stick - this is not under version control, yet.
  • And yes, I have backup copies of all code for the "baseline". I had to since EGit, when you put the code under source control, moves it from my Eclipse workspace into the git repository on the USB drive. So if something goes crazy while learning, I can easily recover. I have not made major changes yet to the code, since I am still learning.

Note: Using Github is not an option.

Purpose/Goal:

What I am trying to do is keep the code as much in order, with version control, as possible by using Git, but in setting it up at work, for some reason I'm a bit afraid it won't work the same when I get home. (Side note: I sense a "This is of the beauty of git." type answer somewhere.)

My questions are:

  • Using Git as a version control system, what is a best practice for this type of setup?
    • Should I leave it on the USB stick just use that repository for everything?

Sorry for the length, but I wanted to provide as much information as possible. Thanks ahead of time for any information anyone can provide after wading through my novel.

Wolf
  • 8,482
  • 7
  • 48
  • 92
bovineone
  • 303
  • 1
  • 2
  • 8
  • 1
    Is it not an option to create a repo on a server in your office and give yourself SSH access? – JamesHalsall Jun 17 '11 at 18:25
  • @Jaitsu - I probably could set up my own server for that (probably Ubuntu). – bovineone Jun 17 '11 at 18:28
  • yeah, it's probably slightly more elaborate but it has the added benefit of being accessible from wherever you are (USB stick or not) – JamesHalsall Jun 17 '11 at 18:29
  • 6
    @Jaitsu: For some people, carrying a USB stick may be easier than carrying an internet connection. – John Bartholomew Jun 18 '11 at 19:18
  • @John Bartholomew, good point... would definitely prove useful, but the whole idea of git is to be disconnected... he would have a local repo on his machine, and the remote repo would be pushed to when he had a connection – JamesHalsall Jun 19 '11 at 00:08

5 Answers5

20

Try keeping a bare repo on the usb stick and clone it to the machines you are working on.

Before you pack up for the day or complete to remove your stick, push your changes back to the "origin" (which is the bare repo on the stick).

When you open up on your other workstation (home?) fetch your changes.

Dave G
  • 9,152
  • 33
  • 40
  • I could do that too. See my reply to Daenyth above. :-) – bovineone Jun 17 '11 at 18:30
  • @bovineone Ok this is a little meta ... so a bare repository is just the database which is a full history of every commit ever merged into it. Basically it's the contents of the .git folder you have in your "working" copy. git records ALL commits and when a clone/push/pull operation transfers all items in the database (with intelligence so collisions don't occur) to/from the target. – Dave G Jun 17 '11 at 18:33
  • 1
    @bovineone to give you an idea on what I was doing was I had dropbox installed on my computers in two locations. I created a git repo locally (working copy), added my code to it. I then cloned that as a bare repository into my dropbox folder (which was automatically uploaded to dropbox). I then modified my working copy to reflect that the folder placed in dropbox was the "origin" and upstream from my working copy. Any time I pushed changes they were sync'ed off to the cloud and when I got to the other machine I would do a pull from the dropbox folder. – Dave G Jun 17 '11 at 18:35
  • @Dave G - *light bulb* I get it now. My Version Control experience has primarily been in CVS. So, my mindset is still adjusting. :) I have directions (found from here of course) on working with a USB stick as a remote repository. I can adjust those to where Dropbox is the remote repository for pushing/pulling. I'll work on the "origin" stuff too. Still learning. – bovineone Jun 17 '11 at 18:43
  • Cool deal - yeah it took me a little while to get my head wrapped around it as I too have been primarily CVS & SVN which are centrally located. The whole thing is very strange but once getting past that it really rocks. – Dave G Jun 17 '11 at 18:50
  • 1
    Ok, done and done. Local repo is under F:\Repo - Remote is C:\Users\\Dropbox\Repo. Did "git clone --bare . from F:\Repo". Added "dropbox" as a remote repository. Did "git push dropbox master" and that seemed to work. I'll try a clone from it when I get home and add a few more things to my Repo. Thanks for the help. – bovineone Jun 17 '11 at 19:03
  • I got it working. Now I have to remember to Merge my changes when I pull from the bare repository on Dropbox. I cloned just fine to a test VM at work. :) Thanks for the help. – bovineone Jun 18 '11 at 04:10
  • 1
    Just a nudge, but if you could accept one of the answers that would be swell :-) – Dave G Jun 20 '11 at 15:28
  • @Dave-G (or anybody) Question -- is putting the bare repo on the "remote" the only option? Can you have two "live" codebases and cross-commit? Like instead of `Comp1 bare (usbkey) Comp2`, which means you'd need to clone and push/pull on each other computer, `Comp1 usbkey`, so I could plug in the usbkey and work directly from that, then go home and pull to `Comp1`? – drzaus Aug 07 '13 at 01:44
  • I don't believe there is any issue doing what you're suggesting. I was interested in minimizing the information set for transport more than anything else. There is nothing saying you couldn't have a working copy on the usbkey and push/pull however you like. – Dave G Aug 07 '13 at 05:51
10

Using the USB stick to keep the code and the repository on is one option - you get the advantages of portability and version control.

But, another way to do this is to keep a bare repo on the USB stick (or dropbox) and on each machine that you want to use the code, make a clone of this. When you finish doing what you are doing you can just push your changes upstream (to the USB stick or Dropbox or wherever).

Having a bare clone portable means that if you forget (or $DEITY forbid) lose the stick in it's travels, you won't be left holding your…without any code to work on. You can recreate a clone from any of the repositories if you've lost the key, and, if you forget the key at home or work or somewhere else, there is always something you can do on your project and merge the changes with the key when next they are together.

Abizern
  • 129,329
  • 36
  • 198
  • 252
  • Thanks for the reply. I am going to try the Dropbox method. I just created an account and installed the client. Here goes nothing. – bovineone Jun 17 '11 at 18:55
  • @bovineone It's fine. I use it all the time. Just a quick tip; when you clone your repository, use the `--no-hardlinks` option. – Abizern Jun 17 '11 at 18:59
  • Thanks! I'll remember that. :) – bovineone Jun 18 '11 at 04:35
  • Another benefit I see to designating the USB drive as the "remote repo" for pushing changes would be to extend the life of the device by saving on writes. That is, all revisions are being done locally, branches, etc. until you're ready to push back to the USB drive at the end of the day :) – Matt Borja Jan 09 '16 at 21:13
2

Just a suggestion:

I use Truecrypt with my USB sticks. My code goes into a tc volume. In case I lose the stick - which is fairly common with those things - the finder doesn't get my code.

Gene De Lisa
  • 3,446
  • 1
  • 18
  • 34
2

One common solution is to keep a bare repo in dropbox and push/pull with that to keep your computers in sync.

Daenyth
  • 31,276
  • 11
  • 75
  • 115
  • So, I played around with bare repo. Does it just keep track of the changes you have made, but it doesn't actually keep the source code in the bare repository? - And I've always wanted to have an excuse to work with Dropbox. This might be it. :) – bovineone Jun 17 '11 at 18:30
  • I've had success keeping a full repo on dropbox, with `origin` on github. I can work away at three different machines, and they're (almost) always in sync, and just do a `git push` occasionally to make sure I have a backup somewhere else. – Ben Straub Jun 17 '11 at 18:36
  • @bovineone: That's pretty much what a bare repo does, yes. The reason for using bare is to (1) save space in dropbox and (2) not clutter dropbox with dozens of iterations of file changes in your working tree. – Daenyth Jun 17 '11 at 18:37
  • Ok. Yea, Dave G suggested the same thing. I just setup Dropbox. Now to configure stuff and then try it at home later. Thanks! – bovineone Jun 17 '11 at 18:48
1

Another way is via bundles. This assumes you are using an independent machine, see how-to-use-git-in-a-sneakernet-environment

Community
  • 1
  • 1
Philip Oakley
  • 11,745
  • 8
  • 42
  • 63