30

Don't know whether this is fully supported in Git would be excellent if it is as it could make things a lot easier, basically I have a project am working on in folder X and when I get it to a particular stage I want to push it to folder Y on my computer again.

If this is possible great, what would be evener better is whether it is possible with either GitHub for Mac or Tower for Mac.

Aran
  • 3,298
  • 6
  • 32
  • 33
  • Is there a reason that a branch wouldn't suffice? I would think you would create a branch, edit, and then merge that branch when you are that the "particular stage". I guess I'm slightly confused on the separate folders on the same machine with effectively the same repo. – rnicholson Aug 07 '11 at 23:30
  • 2
    Reason for separate folders is I want to keep development and test environments of my project separate. Also the other folder is where my web server runs from. – Aran Aug 10 '11 at 22:29

2 Answers2

41

It is absolutely possible - what you probably want to do is create a "bare" git repository in folder Y (git init --bare) and then add that file location as a remote:

git remote add Y file:///path/to/Y

I assume GitHub for Mac or Tower for Mac would handle this like any other remote.

dahlbyk
  • 75,175
  • 8
  • 100
  • 122
  • There's a caveat. Wherever you create a repository `git` needs to be able to lock. It won't always be possible for remote mount points. – cprn Nov 09 '17 at 17:05
  • I don't understand what `file:///path/to/Y` refers to. Do you simply replace `file:///path/to/Y` with the fully qualified path to the directory you wish to be your repository? (I tried replacing that with `C:\Users\exampleremote\` and it *seemed* to work). – Minh Tran Apr 24 '18 at 20:35
  • @cprn What do you mean when you say `git needs to be able to lock`? Also, by `remote mount points`, do you refer to hosts on a network? (I'm interested in setting up a remote repo on a host (dedicated pc) across a LAN network). – Minh Tran Apr 24 '18 at 20:38
  • @MinhTran I think absolute Windows path can be used as well (don't have Windows system at hand to check that). – cprn Apr 25 '18 at 12:34
  • 1
    @MinhTran There are certain file systems that don't allow file locking - that's what git does to make sure no two git instances will concurrently modify the same repository overriding each other's changes and possibly breaking it. In *nix systems attaching a resource to a tree is called `mounting`. You can attach local or remote location and target it using a path, this includes resources over LAN, but you have to make sure the remote resource uses file system that allows locking (some allow locking only locally, some allow remote locking, some don't allow locking at all). – cprn Apr 25 '18 at 12:39
-2

I would assume that you want to push to Y so that you can have a checked out folder of the "previous good" changes elsewhere. The answer from @dahlbyk suggests a bare repo. If you are going that way, you can ( and probably should) rather have a branch in the same repo.

Other than that, just clone the git repo in X into Y ( non-bare ) and either git pull from Y or setup a remote like @dahlbyk from X and push to Y. Make sure receive.denyCurrentBranch is set to false or a different branch from the branch you are pushing is checked out in Y

manojlds
  • 290,304
  • 63
  • 469
  • 417