101

How can a team of four people use Git (specifically Github for Windows) to push local changes to a shared network drive?

Right now (without Git) we have to copy the files from the network drive to our local machine, edit the files, and then re-upload them to the shared network drive. This is a painstaking process that can lead to lots of errors, but it seems like something Git could help us with.

Can we simply install Git on the shared drive and go from there?

user1549303
  • 1,019
  • 2
  • 8
  • 3

3 Answers3

141

Not sure if you found something that works for you or not, but I have a writeup on how to do that very thing on a windows network drive:

http://tony.halcyonlane.com/blog/2011/09/22/Using-git-at-work-on-a-Windows-network-drive/

From a cmd prompt change to your mapped drive.

$ cd g:

Then cd into your soon to be git repository.

$ cd scripts

Then create an empty git repository. If you do not use the --bare option, you will have issues so don't leave that out.

$ git init --bare

Now if you don't have a local git repository yet, then you can clone your new repository wherever you like by navigating back to your local drive.

$ c:

$ cd work/scripts

$ git clone file://g:\scripts

When you clone, you automatically get a remote called "origin" and you can push to the server for safe keeping any time you make changes locally.

$ git push origin master

If you already have a git repository and you just want to push out to the shared drive then you can do this from within your local git dir.

$ git remote add origin file://g:\scripts

$ git push origin master

Community
  • 1
  • 1
Tony Eichelberger
  • 7,044
  • 7
  • 37
  • 46
  • 1
    Thank you -- I did exactly this for a personal project on my home network. – Martin Snyder May 03 '13 at 00:41
  • I followed these steps but get the following errors when I run git push origin master error: cannot spawn sh: No such file or directory fatal: unable to fork – NickStees Jun 15 '16 at 18:16
  • Thank you. Took a long time to find this answer – Simon Huckett May 05 '17 at 11:18
  • 1
    For anyone who doesn't have their shared drive mapped, there's pushd (and popd) to create a virtual temp drive to navigate to ([see link](https://superuser.com/a/399885)) – LoJo Apr 05 '18 at 18:11
  • 1
    can I put //192.168.1.1/shared/folder/repobare.git instead of the mapped G:\scripts? – Zennichimaro Jan 07 '19 at 02:47
  • shouldn't you create a directory `.git` within `scripts/` ? – 3pitt Jul 23 '19 at 13:53
  • For anyone who gets the error '...No such file or directory...', try mapping a network drive past the folder(s) you don't have access to. Git tries to search parent directories – seadoggie01 Sep 14 '21 at 13:02
  • This works fine. However, when calling `git status` on the shared folder after `git init --bare` I get the following error: `fatal: detected dubious ownership in repository at 'shared_drive'`. I know I can silence this error related to me not being the owner of the shared folder, and then work normally. But I am wondering whether that will cause any issues in the long run (Note: I am the only developer who usually modifies scripts in these shared folders) – Alberto Agudo Dominguez Apr 10 '23 at 08:35
27

Our team currently does exactly this. Every developer has the following:

  1. Git installed on their local machine
  2. Access to their own personal shared drive (L:)
  3. Access to a shared group drive (V:)

We have the "remote" repository (set up using init -bare) on the V: drive, and everyone has a clone on their personal L: drive. All changes are made to the L: drive and pushed up to the V: drive, which are then pulled down later by the other developers to their respective personal repositories on their L: drives. This works without any problems, and mitigates the need for a Git server.

eykanal
  • 26,437
  • 19
  • 82
  • 113
  • 1
    Okay, great! Do I need to first create a local repo, and then set up a remote of that repo on the shared drive? – user1549303 Jul 24 '12 at 17:56
  • 1
    @user1549303 - That's how we do it. You can create the local repo (our `L:` drive repo) using `git init`, and then create the remote (our `v:` drive one) using `git clone --bare` (or a `git init --bare`, and then a push from the `L:`). – eykanal Jul 24 '12 at 18:00
  • @eykanal - My Team currently uses an ancient, horrible source control library and we are looking to switch to git. One thing our current library lets me do is see who has checked out a file but forgot to check in the changes. With git, all repositories are local, so how can you know if someone forgot to push to "v:"? – Kevin Buchan Jul 25 '12 at 17:34
  • 5
    @KevinBuchan - I suggest you post your comment as a new question. – eykanal Jul 25 '12 at 18:11
  • 2
    Ho does Git react when two developers try to push to the same shared repository (say V:) at the same time? Have you had any problem with concurrent push operations? – Jordi Sep 11 '17 at 16:33
  • @Jordi - It's a simple race condition, first user wins. [Longer answer on this specific topic over here](https://stackoverflow.com/a/4644294/168775). – eykanal Sep 11 '17 at 17:27
2

You can add another remote pointing to your network drive (git remote)

Then you can push pull similar to what you do with github

bluesman
  • 2,242
  • 2
  • 25
  • 35