0

WHAT I AM TRYING TO ACHIEVE---

I know little about git and trying to learn it. I don't have git installed in my server.

Hence I am trying to create a folder(Git Repos Folder) in my system that will act as a directory of repositories. (Like repositories created in GitHub) and another folder(Git Clones Folder) where I can clone the repos and work on them.( Like local clones of github repositories).

I want to be able to commit and push from any of the repositories in Git Clones Folder to the respective repositories in Git Repos Folder.

WHAT I HAVE TRIED -

I created a repo named praveenpuglia.com inside Git Repos Folder and ran git init to make it a git repository.

Next I cloned the repo as praveenpuglia.com inside Git Clones Folder using git clone D:/Git Repos Folder/praveenpuglia.com

I put a readme file , staged and committed it.

When I try to push the changes to the master, I get these errors

Pushing to D:/Git Repos Folder/praveenpuglia.com
remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: with what you pushed, and will require 'git reset --hard' to match[K
remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To D:/Git Repos Folder/praveenpuglia.com
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to D:/Git Repos Folder/praveenpuglia.com'

What am I doing wrong and how do I set it up? I have tried few of the available answers here but could not understand.

Praveen Puglia
  • 5,577
  • 5
  • 34
  • 68

1 Answers1

1

If you want to push to the remote repository it must be created as bare repository. You can convert remote repository to bare by:

git config --bool core.bare true
ceth
  • 44,198
  • 62
  • 180
  • 289
  • I did that and pushed from the clone. It got pushed. however the pushed file is not reflected in the **D:/Git Repos Folder/praveenpuglia.com** folder. – Praveen Puglia Feb 23 '14 at 15:38
  • Try to check 'git log' on your remote repository. Do you see all your commits ? – ceth Feb 23 '14 at 15:39
  • log shows the commit although it does not show the readme file. Author: Praveen Puglia Date: Sun Feb 23 20:38:48 2014 +0530 Initial Commit. Readme added. – Praveen Puglia Feb 23 '14 at 15:44
  • It is correct behaviour for the bare repository. You can try to clone another copy of your remote repository and check that your readme file present on clone repository. – ceth Feb 23 '14 at 15:49
  • Great. So the new one has the readme but I am still confused as to what's the role of a bare repo then? Would love some education on it. – Praveen Puglia Feb 23 '14 at 15:54
  • May be it helps you to get the difference between the bare and non-bare repositories https://stackoverflow.com/questions/5540883/whats-the-practical-difference-between-a-bare-and-non-bare-repository – ceth Feb 23 '14 at 15:55
  • I am starting to wonder how it works for github when you create a repo there, clone it locally, commit and push the changes. The files are also reflected in the github repo too right? How does this happen when that git repo has a working tree? – Praveen Puglia Feb 23 '14 at 16:22
  • I cannot answer to this question because I am not working in the GitHub :) But you can install GitLab (it is very similar to github) locally and check it. – ceth Feb 23 '14 at 16:26
  • `it must be created as bare repository` - that's not true, as should be obvious from the error message. It _should_ be a bare repo, but that's not "must". – AD7six Feb 23 '14 at 17:03