2

I'm new to git, so forgive me if I've missed the boat completely. I am coding sites on my laptop and in addition to Dropbox I would like to have a backup of everything that I've done stored elsewhere. This is when I learned about git. I understand that it keeps track of all of the changes made (and committed), but what happens to the actual files that I've changed? What I'm asking is probably best explained by an example.

I have set up a git repo on my laptop to manage all of the changes made to MySite/ and all of its files and folders (index.php, img/, css/, etc.). I have also created a --bare git repository on a flash drive. I have pushed the original repo to that location. I am able to use git log to successfully view the history, but when I access the flash drive I notice that the contents of MySite/ are not there (or at least viewable). What do you suggest that I do to be able to work from the flash drive and then later push those changes to the laptop while still being able to work from the laptop as I am used to?

ServAce85
  • 1,602
  • 2
  • 23
  • 51

2 Answers2

4

Just have both be non-bare repositories. It's simplest probably just to delete the bare repo (since it sounds like there's currently nothing unique to there), then run:

git clone /laptop/project /thumbdrive/project

where /laptop/project is the main non-bare repo, and /thumbdrive is your mounted thumbdrive.

Now, /thumbdrive/project is a non-bare repo. Thus, you have two non-bare repos (meaning both have working directories), and you can feel free to work and commit with both of them, then pull (or push if you're careful) between them.

Bare repos are used when you want a copy you will not work directly out of (e.g. a pure backup, mirror, or server).

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • 1
    Pushing into a non-bare repository is potentially dangerous, and you'll get warnings about it. The really important thing is that you don't want to push to a checked-out branch. It's usually much better to fetch/pull into a non-bare repo. Another option would be to have a non-bare clone on each machine, and use a bare repo on the thumbdrive as a central repo - plug it into your machine and push/pull as you would with any central repo. – Cascabel Apr 07 '11 at 17:53
  • @Jefromi, true, it's simpler to `pull`. But pushing is an option, if you're careful. – Matthew Flaschen Apr 07 '11 at 17:55
  • OK - just tried it and it seems to have done exactly what I was asking for, but I have one question... When pushing and pulling between them, how do you specify the location? For example, the way I originally set it up I had named the flash drive `flashdrive` and I would simply use the command `git push flashdrive`. How would I do that now? – ServAce85 Apr 07 '11 at 17:56
  • 2
    @ServAce85: `git remote add flashdrive /path/to/flashdrive/repo` (or `git remote set-url flashdrive /path/to/flashdrive/repo` if the remote already exists.) – Cascabel Apr 07 '11 at 17:57
  • Thanks for all of the great help. – ServAce85 Apr 07 '11 at 18:04
1

The files are there - they are inside the various git folders, but they are stored as sets of differences.

You can always extract a set with "git pull" but you shoudln't try and edit git's own files - you will break something. Just treat the git folder as a black box and commit/pull/push files from it

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263