How to: create a "remote" git repo on your local disk drive

ETA: slightly more detailed blog post: https://www.deplorablemountaineer.com/tutorial/keeping-your-git-repo-local/

Why would you want to do this?

  1. you don’t want to make it public, and don’t want to pay for a private Github account

or

  1. you don’t want to fool with Git LFS

Of course, this doesn’t share your repo with others. If you still want to do that, you need to use OneDrive or DropBox or something.

Personally, I have an external drive on windows, mapped as my Z: drive, and that makes it a good backup drive, not the same drive that the original project is on. For me, that’s a great place for a local “remote” git repo.

Here is how to do it (assuming you use Sourcetree):

Assuming you already have a project started and committed locally as a Git repo, but you have not pushed it to a remote repo yet:

  1. Use SourceTree as you normally would to stage and commit the project. Let’s just say the project is called my_project for now. Lets say you want to store the remote repo as Z:\repos\my_project

  2. While still in SourceTree, click the Terminal button near the top-right of the window.

  3. In the Git Bash terminal window that appears, type the following to create the new repo (changing path and project name to what you need it to be):

git init --bare /z/repos/my_project

Note, git bash uses /z/ instead of Z:\ for the root of the Z drive, and the directory slashes go forward instead of backward.

  1. Still in the Git Bash terminal window, type the following to clone your project to that new repo you created (while you are still in the project directory that Git Bash automatically started in):

git clone --bare /z/repos/my_project

  1. Now we need to connect the local project in SourceTree to the remote we just cloned. To do this:

  2. In SourceTree, select the Repository menu from the top menu and select the “Add Remote…” item.

  3. In the popup, with the Remotes tab active, click the Add button

  4. For Remote name: check the Default Remote.

  5. For Url/Path, type /z/repos/my_project (or the one that you used above)

  6. Ignore the Optional Extended Integration section

  7. Click OK, then click OK again.

  8. As a test, click Push to push your last commit (make a new commit first if you need to). Check the “Push?” checkbox, and leave local and remote branches as Master, and leave “Track?” checked.

  9. Click the Push button at the bottom.

  10. Depending on amount to push and speed of the disk drive you push to, it might take a while. (My Z drive is slow, being an external networked drive)

  11. It should finish with no errors: no news is good news.

Privacy & Terms