Jazimov
Jazimov

Reputation: 13282

Using Network Share As Visual Studio 2015 Git Remote

I feel like I'm missing something because this need should be a very common one...

Assume this scenario:

The Windows Server is available to all five developers using a UNC path that includes the IP Address (such as "\1.2.3.4\C$\repo\temp").

All I want to do is place a Visual Studio solution on the file server in the target path \1.2.3.4\C$\repo\temp. Once the solution is there, I want each developer to clone from it and develop using a local repo before pushing changes back to the file server.

Here are my questions:

  1. In this case, isn't the file server technically a "remote repo" with respect to the five developer workstations?
  2. If that answer to (1) is Yes then it seems that remote repos in Visual Studio must be defined as https:// targets (UNC paths don't work). Can a remote repo be defined as a UNC path on the network?

Perhaps the term "remote repo" is very specific in Git parlance...such that a remote Git repo must be either a third-party repo, such as GitHub, or some other internet-based endpoint. But that just doesn't seem right. I don't understand why the remote repo can't just be a file path on the local workstation or on any other available path on the local network.

Perhaps the file server in my example isn't technically a "remote repo"; it's okay with me if it actually is a "local repo" on the network--if that's the case, I'll learn to refer to it as a local repo... Ultimately, all I care about is that the file server will hold the team's "master" branch, and will be used to create builds. All developers will make pushes back to the file server repo.

How can I set up such a networked file server and use it as my team's master repo? If you don't know the Visual Studio 2015 way of achieving this then I would still accept answers that explain how this would be done using the Git command-line tools...

Upvotes: 3

Views: 2477

Answers (2)

patthoyts
patthoyts

Reputation: 33203

When I've done this in the past we used unix-style UNC paths: ie: //SERVERNAME/Share/repository.git and ensure the shared repository is a bare repository (ie: git init --bare repository.git). Adding .git to a repository directory name is just a common convention to indicate it is a bare repository.

Example with a non-bare remote share (git version 2.7.0.windows.1):

C:\Code>git ls-remote \\SERVER\c$\Code\Build
fatal: '\SERVER\c$\Code\Build' does not appear to be a git repository
fatal: Could not read from remote repository.

C:\Code>git ls-remote //SERVER/c$/Code/Build
ad081d35144157551e3728d6deadf19ae106ced0        HEAD
ad081d35144157551e3728d6deadf19ae106ced0        refs/heads/master
ad081d35144157551e3728d6deadf19ae106ced0        refs/remotes/origin/HEAD
ad081d35144157551e3728d6deadf19ae106ced0        refs/remotes/origin/master

Given the response on the first attempt it's clear we have a quoting problem so doubling the backslashes can solve it -- or switch to forward slashes. You can use a file:// URL scheme, but you still need two slashes to indicate the UNC server part so:

C:\Code>git ls-remote file:////SERVER/c$/Code/Build
ad081d35144157551e3728d6deadf19ae106ced0        HEAD
ad081d35144157551e3728d6deadf19ae106ced0        refs/heads/master
ad081d35144157551e3728d6deadf19ae106ced0        refs/remotes/origin/HEAD
ad081d35144157551e3728d6deadf19ae106ced0        refs/remotes/origin/master

Upvotes: 2

thebjorn
thebjorn

Reputation: 27311

When you create a central repository (that will be shared with other users), you should create it with the --bare option:

git init --bare myrepo.git

this implies that there is no working directory created, and there is no top-level .git directory (instead the contents that would "normally" be in the .git folder will be at the top level).

A bare repository requires the users to use the clone/pull/fetch/push commands to interact with the repository (as opposed to add/commit which interacts with local repositories).

The convention is to name bare repositories with a .git extension. While git itself doesn't care, much of the tooling expects it.

So, if you create a bare repo on a UNC path you should be able to use it directly

\1.2.3.4\C$\x\y.git

I would probably share the directory explicitly on the server so you get a nicer looking path...

Upvotes: 1

Related Questions