Git init –bare – Not Working on working tree
I am following the examples here
Basically I want to create a git repo i can push to on a server from my desktop…
[host ~]$ mkdir project.git [host ~]$ cd project.git [host project.git]$ git init --bare [host project.git]$ exit
[local ~]$ cd project [local project]$ git init [local project]$ touch .gitignore [local project]$ git add . [local project]$ git commit
On host if i CD into the directory.. I am shown the following files (which usually sit in the .git dir)
HEAD branches config description hooks info objects refs
On local I then create a remote push:
git remote add origin ssh://XXX@XXX/home/XXX/XXX/
It pushes says it has worked…
Counting objects: 3, done. Writing objects: 100% (3/3), 210 bytes, done. Total 3 (delta 0), reused 0 (delta 0)
However when I go back to the working folder on the server, there is nothing there.. it is just the .git files listed above.
I have done this before and it worked this way… just this time I must be doing something wrong.
If I try to create the repo on the server without –bare … then I get this error on push
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: remote: error: You can set 'receive.denyCurrentBranch' configuration variable to 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'.
UPDATE AND RESOLUTION….
I found this which works really well
Essentially use a –bare then have hook which copies your latest commit to a working directory!
2 Solutions collect form web for “Git init –bare – Not Working on working tree”
git init --bare creates a “bare” repository – one that does not have a working directory associated with it. What you are seeing is what is expected. If you want a separate repository that has a checked out working directory associated with it, don’t use the
--bare option, but note that doing so has additional implications, because
git push acts differently when the remote is not a bare repository, in order to protect you from losing any unstaged/uncommitted changes you may have in the remote.
What you see seems correct. The .git files you see in that folder (and a lot of it in the objects directory) contains all your git repository.
When you make a “bare” repository, this prevents anybody else to edit the files directly there (on your host machine), not having the project checked out with all your source file is one of the thing that would prevent such editing.