Skip to content

Git Using File Share

Kenneth Kasajian edited this page Mar 1, 2018 · 3 revisions

This page assumes the reader is an experienced user of git.

This assumes git and git tools (differ, merger) are configured. If not, see Git - General Prerequisites

Using a \\UNC file share as a git repository

Method 1. Create Repository in a file share and then clone it locally

Let's create a new local directory we will clone into.

C:\> mkdir MyRepos

C:\> cd MyRepos

C:\MyRepos> 

Let's create a directory in a file share

We'll assume that \\fserver\r is an empty file share. And we're going to create a directory in there call mygame.git. The .git extension on the directory is not necessary but is a nice convention to remind yourself later that the folder contains a git repository. Create directory \\fserver\r\mygame.git:

mkdir \\fserver\r\mygame.git

Let's create an empty git repository in \\fserver\r\mygame.git

Use the pushd command to simultaneously map a drive and CD to the folder:

pushd \\fserver\r\mygame.git

Now create a bare repository and return

git init --bare

popd

Let's clone \\fserver\r\mygame.git

C:\MyRepos> git clone file:////fserver/r/mygame.git
Cloning into 'mygame'...
warning: You appear to have cloned an empty repository.

C:\MyRepos> cd mygame

C:\MyRepos\mygame>

That's it. Add, Commit, Push and pull as desired.

Method 2. Create Repository locally then connect it to a new repository in a file share

Let's create a new local repository with some stuff in it.

C:\> mkdir MyRepos

C:\> cd MyRepos

C:\MyRepos> mkdir mygame

C:\MyRepos> cd mygame

C:\MyRepos\mygame>

C:\MyRepos\mygame> git init
Initialized empty Git repository in c:/MyRepos/mygame/.git/

C:\MyRepos\mygame> echo. > readme.md

C:\MyRepos\mygame> git add -A

C:\MyRepos\mygame> git commit -m "First Commit"
[master (root-commit) a8a02c1] First Commit
 1 file changed, 1 insertion(+)
 create mode 100644 readme.md

Let's create a directory in a file share

We'll assume that \\fserver\r is an empty file share. And we're going to create a directory in there call mygame.git. The .git extension on the directory is not necessary but is a nice convention to remind yourself later that the folder contains a git repository. Create directory \\fserver\r\mygame.git:

mkdir \\fserver\r\mygame.git

Let's create an empty git repository in \\fserver\r\mygame.git

Use the pushd command to simultaneously map a drive and CD to the folder:

pushd \\fserver\r\mygame.git

Now create a bare repository and return

git init --bare

popd

Let's connect the local to the remote repository

C:\MyRepos\mygame> git remote add origin file:////fserver/r/mygame.git

C:\MyRepos\mygame> git push --set-upstream origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 203 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To file:////fserver/r/mygame.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

That's it. Add, Commit, Push and pull as desired.