2

I cannot understand how to work with Git (and Visual Studio 2015).
What I'm doing:

  1. Copy one of my project to a new folder. Init repo there.
  2. Clone the repo
  3. Modify one of the .cpp files in the cloned repo
  4. Stage and commit the changes.
  5. Get the error:

Failed to push to the remote repository. See the Output window for more details.

Output:
Error encountered while publishing branch to the remote repository: Local push doesn't (yet) support pushing to non-bare repos.

After more than an hour of google search I have no idea what to do.
Why cannot I just create a repo (сonsider it as 'remote'), then clone (to any considered 'local' repo) it and then commit & push new local changes to the 'remote'?

Simply put,
I just try to make one folder with 'remote' repo and the other with 'local' and try to push from 'local' to 'remote'. Is it a wrong logic?

Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
  • Which VS version? Looks like 2015? – jessehouwing Jun 26 '17 at 12:18
  • How come the *remote* repo has a working directory? Git itself prevents this. Newer versions allow you to push to such repos, to allow "push to publish" scenarios – Panagiotis Kanavos Jun 26 '17 at 12:21
  • @VladimirBershov what are you trying to do? Why does the *remote* repository have a working directory? For git deployment scenarios you *can* configure the remote to accept pushes. If you try to push to a colleague's repo though you should reconsider - pushing would delete any local changes – Panagiotis Kanavos Jun 26 '17 at 12:28
  • @VladimirBershov did you try to push to a local "Deployment" repository with code that you want to send to others? – Panagiotis Kanavos Jun 26 '17 at 12:29
  • @PanagiotisKanavos I just try to make one folder with 'remote' repo and the other with 'local' and try to push from local to remote – Vladimir Bershov Jun 26 '17 at 12:31
  • But the "remote" wasn't created as a bare repo? That's what the error is about. You can either start again, making sure the "remote" is bare, you can convert it to a bare repo [as shown in this SO question](https://stackoverflow.com/questions/2199897/how-to-convert-a-normal-git-repository-to-a-bare-one) or you can configure the remote to accept updates to the working directory [as shown in this question](https://stackoverflow.com/questions/1764380/push-to-a-non-bare-git-repository) – Panagiotis Kanavos Jun 26 '17 at 12:43
  • You could also create a new bare remote, called eg `backup`, *pull* from your working repo, add the `backup` repo as a remote to your working repo and just push whenever you need to – Panagiotis Kanavos Jun 26 '17 at 12:45

1 Answers1

2

The error complains that the remote you currently use is a non-bare repo, ie it has a working directory. I assume you want to create a "backup" repo on your local machine, eg on a thumb drive or simply a different folder.

The easiest solution is probably to create a new bare repo and add that as a remot to your working repo. For example, on the H: external drive, in a BackupRepos folder, add a new bare repo:

git --bare init BackupRepo1.git

This will create a new bare repo in the BackupRepo1.git folder.

In your working repo, add BackupRepo1.git as a remote named backup:

git remote add backup h:\backuprepo\bkprepo1.git

You can now push directly from your working repo to backup

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • Ok, what if I need also to share this 'remote repo' to a several other developers. Simply put, is this a correct way, to create such a 'remote repo' (for example on a network drive or just in a shared folder) for a group of developers for working on one project? Or the right way is entirely different? – Vladimir Bershov Jun 26 '17 at 13:05
  • 1
    All repos are equal as far as Git is concerned. If you want to call one of these the "root" repo, it's entirely up to you. You *could* use a file server to hold your root repo, if the repo is small and the users are few. – Panagiotis Kanavos Jun 26 '17 at 13:19
  • 1
    A slightly better option is to run Git as a service - this way only diff data is exchanged between clients and the repo. A Git server like Gitlab, Gitorious or ... TFS Express is even better. You could also use a hosted git repo, either as the main "root" repo or as an of-site backup. There are a lot of online git providers, like Github TFS Online, Atlassian that offer private repos. Public repos are free – Panagiotis Kanavos Jun 26 '17 at 13:22