Search code examples
gitgit-pushgit-pullgit-fetch

Git - multiple working copies without bare copy in between


Similar to:

I'm trying to figure out the workflow steps to accomplish the following:

  1. Having worked locally on "home", I want to start a repository in W:\DEV\proj1
    • git init W:\DEV\proj1
    • cd W:\DEV\proj1
    • git add *
    • git commit -m"1st home"
  2. I then want to clone this repo to "portable" somewhere else (i.e. a usbkey), lets say P:\DEV\roam1
    • git clone . P:\DEV\roam1
  3. Then I want to be able to do work in either location ("home" or "portable") and sync changes back and forth.
    • (in portable)
      • // new file f1.txt
      • git add *
      • git commit -m"1st portable"
      • git ??? -- sync f1.txt > "home"?
    • (in home)
      • // new file f2.txt
      • git add *
      • git commit -m"2nd home"
      • git ??? -- sync f2.txt > "portable"
    • repeat

Part A) I think I understand how to clone and sync to a "centralized hub", i.e. github or putting a bare repo on a usb stick and cloning from it whenever I'm at a new location, but I'd rather not have to clone from the portable repo every time I want to get work done in a new place. Also, in the case where I just want to look at the file on a computer that doesn't have git installed.

Part B) Another applicable scenario is that I want to use git to basically backup a directory to an external harddrive (which pushing to a bare repo would normally be fine) but I want to access the files on the harddrive on another computer without git installed.


Solution

  • but I'd rather not have to clone from the portable repo every time I want to get work done.

    You won't have to, except to initialize your repo in a new location (in which case, you would clone the bare repo of your usb stick on your local environment)

    Every time you want to get work done, you would:

    • make sure the remote named 'origin' of your local repo points to the bare repo on the usb stick
    • git pull (or git pull --rebase) in order to get potential changes from usb back to local
    • work
    • git push (back to the usb key)

    You need some kind of "centralized/portable" repo to pull from/push to.


    not wanting the "centralized hub" to be a bare repo is that, let's say I go another computer without git and I want to just show someone a file

    I would still recommend a bare repo on the usb stick, but I would add a post-receive hook on that bare repo, in order to update a separate working tree (still on the usb stick)

    See "Want to setup a hook that copies committed files to a particular folder" as an example of such a hook.

    That way, I always have, on my "centralized and portable" git repo hosting environment (ie the usb key!):

    • a bare repo (I can clone/pull from/push to)
    • a full working tree, up-to-date with the latest commits.