I come from SVN and I am not understanding how the whole Git thing works. I’ve created a remote repo, cloned the repo in my local machine – if I make changes to files in my local machine and try to push those files to the exact remote repo I cloned from I get an error like this.
remote: error: refusing to update checked out branch: refs/heads/master
I browsed through some SO questions regarding the same issue and the most popular solution was creating a bare repository and then committing to it. So what happens when I clone from that new repo – would this happen again? Should I keep creating new bare repos for each commit from my local? I’m confused and it will be great if someone can point me in the right direction.
I think I am doing this completely wrong.
Exact steps I am following:
1) Created a directory in remote server – init as git repo
2) Copied all contents I needed into the server
3) Added the content into git and committed them there
4) Cloned the git repo from remote to my local machine
5) Made a change to a file in my local, added the change to my local and committed it.
6) When I try to push changes made in my local to remote using: git push origin
I get the error message. I’m providing the whole error message below.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: Auto packing the repository for optimum performance.
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
! [remote rejected] master -> master (branch is currently checked out)
Shared / remote repositories use a bare format, meaning they have no working copy. Subversion is the same – the central repository does not have a working copy. Working copies are created via checkouts in subversion, and via clones in git.
The problem will not continue to occur if you change the remote repository to bare format.
The workflow is not significantly different than subversion, just an extra step (or two, depending on the commands you use)
When you want to pull changes from others from the remote repo, you do a “git pull” which functions similar to “svn update.”