Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 git Push to Network Drive

I am working on a C++ project with several other people in Visual Studio Community 2015, and we would like to use the built-in git features of VS2015 to manage our project. We would like each user to have a local git repository on their laptop, and then put a Remote repository on the network drive that we push/pull to/from. I would like to know the proper work flow for this particular setup using the built-in git features of VS2015. We DO NOT want to use VS online or Team Foundation Version control or the command line version of git (due to the nature of our jobs we will not have internet access and we do not have access to the command line prompt).

I have tried several things to get this to work without any luck.

First I open the solution in VS2015, then click file -> add to source control -> git, which creates a local repository. I then commit my files to the local repository. So far no problems.

Next I want to create a remote repository on the network drive. In team explorer for the project, I click on synchronization, and it asks for the URL for an empty git repo. I enter the folder on the network drive I want it to use, but I get an error saying it could not find the repository, probably because the folder is empty. Maybe I'm missing it, but there does not seem a way to create an empty git repo in VS2015.

So to try to create an empty git repo, I navigate to File-> new-> Repository, and I create the git repository in the folder on the network drive. I think enter this into the Synchronization -> URL and I get a different error. This error says local push doesn't yet support pushing to non-bare repos. Creating a new repository in VS2015 doesn't seem to create an empty repository.

Next I tried cloning my local repository location to the network drive folder location, which worked. I then go to my local repository settings, and add the remote repository to remotes, which now shows up on the branches explorer windows. I then make a change to my code, go to changes, and select Commit and Push. This time I get another error: "Unable to push because the current branch does not track a remote branch, publish the changes to the remote." When I right click on the local master branch, the publish option is grayed out, so I cannot publish it.

For a work around, I right click on the remote/master branch, and select new local branch with the option "Track remote branch (configure for push and pull with remote/master)" selected. I name this branch local_master, which is now a published branch. I assumed that the option I selected above would allow me to now push and pull changes from my new published local_master branch to the remote/master branch. When I make changes to local_master, commit, and then try to push I instead get this error: "Local push doesn't (yet) support pushing to non-bare repos." I then right click on the remote/master branch and try to merge from my local_master to the remote/master, which says it worked successfully, but my code changes are not in the remote/master.

I have spent almost 8 hours try to get this to work and researching other solutions and have not been successful, and I'm about at my wit's end. Anybody know how to create a remote repository on a network drive, then push/pull from your local repository to the remote repository using the built-git controls in VS2015?

like image 844
dan h Avatar asked Nov 16 '25 08:11

dan h


1 Answers

This is my current workflow:

  1. Create project in Visual Studio with "Create new Git repository" checked.
  2. Do a local commit, with commit message "Initial commit" or similar.
  3. Open the project directory and find the .git sub-directory. This directory is hidden by default, so you need to turn on "Show hidden files and folders" in Windows Explorer to see it.
  4. Right-click .git, Properties -> Uncheck "Hidden", click Apply.
  5. Rename the directory to YourProjectName.git
  6. Edit YourProjectName.git\config in a text editor (I recommend Notepad++ because it has no qualms about saving a file with no extension, which is required. This file cannot be saved as config.txt)
  7. In config: Delete line logallrefupdates = true Change line bare = false to bare = true Save file as config (with no file extension!!)
  8. Copy the whole YourProjectName.git directory to the file share where you want the master repository to live.
  9. Delete your local copy of the repository.
  10. Open Git Bash (or Actions -> Open Command Prompt in VS 2015 Team Explorer) and cd to wherever you want the project directory to live. e.g. cd C:\Users\YourUsername\Documents\Projects.
  11. Clone the repository from it's network path: git clone //repo-server/c/CompanyRepos/YourProjectName.git

Obviously many of these steps can be done slightly differently or out-of-order, but the important concept is to initialize a bare repository on the network share, then clone it as a full repository locally.

The reason you delete your existing repo and clone from the network share is to make sure all of your remotes are correctly configured.

The config edits recommended above are just one approach to converting an existing full repository into a bare repository. Alternatively, if you're creating a new repository from scratch you can just type "git init --bare" in the command window. However, it's worth noting that "git init" and VS 2015's "Create new Git repository" aren't exactly the same; as Visual Studio adds some additional settings after it initializes the repo. These settings aren't vital, but I figured it was worth noting the discrepancy.

like image 95
Dan Bechard Avatar answered Nov 18 '25 22:11

Dan Bechard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!