How do I create/clone a bare repository in SourceTree?
Asked by anon:

I'm new to git, having used other (non-distributed) version control systems in the past. I'm looking to move my department to git, but need an easy-to-use tool for the majority of the team that has no experience in version control. There will be some advanced users, but probably a majority of the team needs a way to version control/backup their work with minimal fuss (and I'd like to stay on a single platform). I like the idea of SourceTree because it is a standalone application (no potentially confusing Explorer extensions for Windows).

So, to the point - I'm going through various tools (and version control systems) to figure out which ones are powerful enough for the advanced users, while simple enough for those less inclined. Step 1 is simply setting up the initial repositories... for DVCS, that would be the local repo and a central repo on a server. Due to company IT infrastructure, the central repo will simply be hosted on a network drive on a server (no SSH/http). Setting up the local repo seems straightforward enough (It looks like it might be a little intimidating for some of our users, but I think I can manage to train them on that part.) But even I can't figure out how to set up the remote repo using SourceTree. The git documentation I read says to do a
> git clone --bare

But I don't see how to do that. I can't even create a *new* bare repo on the server that I could theoretically push to (or initially pull from).

Am I missing something?


Answers:
author: stevestreeting
body: You can't create bare repositories in SourceTree, mostly because you normally only want to do this on a server and SourceTree is a client tool. Hosting your remote via a file share isn't a particularly robust way to do it and I'd recommend you consider either setting up a SSH server, using a cloud host which uses SSH/HTTPS, or alternatively consider something like [Stash](http://www.atlassian.com/software/stash/overview). If you definitely want to do it via file shares then you'll have to create the bare repo on the command line - for creating it's 'git init --bare PATH' rather than 'clone'.

comments: author: anon
body: Thanks for your quick reply.

It's too bad that you can't create a bare repository in SourceTree. Oftentimes we start development locally and then start version control. So it would've made sense for us to follow the process outlined in the Pro Git book at <http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server>. We could have a local repository, make a bare clone, and copy it to our server. But reading further, we'd probably also have to do another git init --bare in order for that to work, which SourceTree would also have to support.

As for file shares, that's the nature of our company's infrastructure. Engineering is a tiny piece of the company, and getting an ssh or http server running on our network is an expensive, painful process. And policy won't allow use to host on the cloud.

But thanks anyway!


author: Eric Anderson
body: You can also add --bare to a clone command on the command line.So it seems that it would be comparatively straight forward for SourceTree to add a Create Bare check box for the clone operation it offers. This would be one part of \[Support for bare repositories\|<https://jira.atlassian.com/browse/SRCTREE-69>\].


author: xmorera
body: Or add a custom action?


author: Eric Anderson
body: Even though "SourceTree is a client tool" there is a strong reason for having support for local (not server) bare repositories.

It is common that one wants to share code between multiple projects. The git-subtree commands are a great way of doing this that many consider to be superior to the older git submodules. However, these require pushing to and pulling from a bare repository.

If one is going to be able to work productively offline (one of the main points of having a *Distributed* Version Control System), then one needs to be able to have a *local copy* of the bare repositories holding code that is shared between projects via subtree commands. Later, when a network connection is available, one can synchronize the local copy with the remote server copy (e.g. at Bitbucket).

To be an excellent client tool, SourceTree should support the use of both subtree commands and local bare repositories that can be optionally synced with remote (e.g. Bitbucket) server copies when network access is available.

This need is also expressed in my comment in issue SRCTREE-69. <https://jira.atlassian.com/browse/SRCTREE-69>


author: David Pilles
body: Since its the top answer on Google, heres a simple way to do this entirely in SourceTree.

Create a local repo you wish to be your bare on the disk you wish to use.

Open it, click Settings\>Edit Config File.

Change bare to true (dont save yet, you will get errors if you try to view a bare repo).

Close the Repo.

Save the config file.

Feel free to delete the bare repo from the list since you cant view it anyhow.

Now you can go into any working repo you like, click Settings, and add the bare repo as a remote, then push.

comments: author: Maciej P
body: Thanks, David,

your solution is very helpful.

Is there any similar simple way to have local LFS storage?

my config looks following:

```
[core]
?? ?repositoryformatversion = 0
?? ?filemode = false
?? ?bare = false
?? ?logallrefupdates = true
?? ?symlinks = false
?? ?ignorecase = true
[remote "ori"]
?? ?url = D:\\LocalOriTest\\.git
?? ?fetch = +refs/heads/*:refs/remotes/ori/*
[lfs "D:\\LocalOriLFS\\.git"]
?? ?access = basic
[lfs "D:\\LocalOriLFS\\.git"]
?? ?locksverify = false
[lfs "D:\\LocalOriLFS\\.git"]
?? ?access = basic
[branch "master"]
?? ?remote = origin
?? ?merge = refs/heads/master
```

When pushing I am receiving the following message:

```
git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v --tags ori master:master
Pushing to D:\LocalOriTest\.git
Remote "ori" does not support the LFS locking API. Consider disabling it with:
$ git config lfs.https://d/\LocalOriTest\.git/info/lfs.locksverify false

Uploading LFS objects: 0% (0/1), 0 B | 0 B/s, done
batch request: Unable to open connection:
Host does not exist: exit status 1

error: failed to push some refs to 'D:\LocalOriTest\.git'
Completed with errors, see above.
```


author: LetTheWritersWrite
body: This is 3 years late but I wanted to make sure you understood that this very possible. Not sure why Steve says it's not possible. (You can't do it in Source Tree but it's very easy terminal commands)

You create your bare repo on your server or shared drive in your case with some simple commands in the terminal (which I'll let you google to keep this on topic). Source tree has a button to launch it at the top. Note:this is a third party application called MINGW32 that emulates a bash environment. But that's it, real simple git init --bash command. Just create it in a directory that will be secure.

Your central repo will just stay there. You never have to touch it again because the idea is that you're doing the push and pulls from your local repos.

Create your local repo in source tree. Then real easily add the remote repo by going repository-\>repository settings then Add.

Give it a name such as "origin" and the URL/path will be the path to your bare repo you created.

Alright, now you your local and remote repos are connected.

One special note. A bare repo doesn't look like a normal git repo. You won't see any of your working files in there. Don't ask me exactly why this is, it's just the way git is designed and has to do with the fact that a bare repo is not a working tree.

if you want other users to also push to that central repo, you can clone it to their local computer with source tree very easily. Just click the clone/new button and in the source path, enter the path to the bare repo and choose your destination path. Super simple.

now you can have many users pushing changes to the central repo.