Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Visual Studio GIT sync with local/network file folder as remote/origin

I have a local GIT repo with commits but so far unsynced. I created it as per https://stackoverflow.com/a/20004092/586754 which basically results in the local part of the repo with no remote/origin.

I don't have a (company) GIT server but a Onedrive for Business account that seems perfect to at least backup the repo in case the dog eats the machine. (Plan for later is to migrate to comany VCS, which is SVN, once things have stabilized.)

I know that GIT can sync to a file system, but.. how to do it?

  1. Since I already entered some wrong data as a remote repo in Visual Studio (it asked when I went for the "Sync" option, complained, and now all options are greyed out under "Sync"), how do I change this? Only via the command line like

    git remote set-url origin "C:\Users\Test\OneDrive for Business\Andreas\code\project1"
  2. What is the correct GIT URL for a network share and also for a local share? (In my case, I am most interested in the local Windows share, since I expect Onedrive to be responsible for the backup.)

I have an empty folder as a remote right now (I created full path including "project1") and also am getting errors via command line:

git push --set-upstream origin master
fatal: 'C:\Users\Test\OneDrive for Business\Andreas\code\project1' does not appear to be a git repository
fatal: Could not read from remote repository.

Is anything else needed for initial push? Sor far, I have only used bitbucket/github, where I explicitly created a repo beforehand via web interface.

like image 754
Andreas Reiff Avatar asked Mar 15 '23 22:03

Andreas Reiff

2 Answers

After some more searching..

I had following mistakes:

  1. Git Repo needs to be initialized:

    git init --bare project1.git
  2. Correct folder naming, also

  3. everything needs to be done from commandline

So, if you start from scratch, here is the procedure on Windows (well, it is Visual Studio integration after all..):

  1. Get a location, either locally or on network share
  2. cd into that location and execute (for more info and how to cd into network path, see http://elegantcode.com/2011/06/18/git-on-windows-creating-a-network-shared-central-repository/ )

    cd ""C:\Users\Test\OneDrive for Business\Andreas\code\project1"
    git init --bare project1.git
  3. You can now enter the location as origin in Visual Studio and everything works fine. You can then stop here/VS will succeed with the sync.
    Visual Studio Git Repository on local folder
    If you (like me) added a bad location first and can not change it anymore
  4. continue on the command line, in the folder of the local git repo/source files:

    git remote set-url origin "file:///C:\Users\Test\OneDrive for Business\Andreas\code\project1\project1.git"

    will set the correct remote/origin (this we cannot do in Visual Studio, checked with VS2015)

  5. tell git what branches to use

    git push --set-upstream origin master
  6. Now "sync"ing in Visual Studio should work, you can also do it from commandline (push only) with:

    git push
  7. Test in Visual Studio as well

As for correct URLs on Windows, for a local folder, it is

file:///C:\Users\Test\OneDrive for Business\Andreas\code\project1\project1.git

For a network share, you can either map it to a local drive and use that (same as local folder) or




(see also https://stackoverflow.com/a/2520121/586754 )

like image 53
Andreas Reiff Avatar answered Mar 17 '23 13:03

Andreas Reiff

I worked on this for about an hour. Pretty frustrating. In the end, here is what I had to do.

  1. Create a directory for my repos on my network share.
  2. Used TortoiseGit's Git Clone. Right clicked on my current local repository directory and cloned into my remote repo directory. Make sure to select "Clone into Bare Repo"
  3. Then I right clicked on my original, local, repo and used TortoiseGit to "Push". In the dialog that comes up, I selected the "Manage" button and added the URL to my network drive repo. I completed the push, which was successful.
  4. When I went back to Visual Studio 2017 Community, it was all set up.

I have a mapped network drive that I'm syncing to just as an added backup. I imagine OneDrive is similar.

like image 27
Michael A. Long Avatar answered Mar 17 '23 14:03

Michael A. Long