I have my local dev repo (origin) and a remote repo which I created using git init --bare as recommended here. I also ran git --bare update-server-info
git config --bool core.bare true
Git remote -v shows
origin http://staging.websitename.com (fetch)
origin http://staging.websitename.com (push)
remote ssh://[email protected]/home/user/public_html/staging (fetch)
remote ssh://[email protected]/home/user/public_html/staging (push)
After this and running git push remote or git push -all remote, it goes through and gives me no errors. Why don't I see the files on the remote repo??
Compressing objects: 100% (4121/4121), done.
Writing objects: 100% (4242/4242), 18.70 MiB | 694 KiB/s, done.
Total 4242 (delta 495), reused 0 (delta 0)
Bare repositories don't have working copies so you won't "see" any files. Try doing a git log, you can see the commits. Clone from the bare repo and you'll get files.
The essential point of a --bare
repo is that it does not have a working copy (nor an index), which means there is nothing to get messed-up by a push.
If you want certain pushes (to one or more particular branches) to "auto-deploy", the way to make that happen is to use a git hook in the --bare
repo. The hook—generally post-receive
, although it's possible to use the pre-receive
or update
hooks here—is run on all pushes, so it should check whether the push in question is "interesting" (affects the auto-deploy branch(es)), and if so, trigger the deployment.
The hook is run on behalf of the process doing the push (often ssh as some user, as in your git remote -v
output), so if the deployed files should be owned by another user, you must arrange that somehow. One easy, simple, and reasonable method is to write to file that is set to mode rw-rw-rw-
(write-able by everyone), and have something (such as a cron job) check the file periodically. If written, the cron job—running as the deployment user—can extract the latest version of the appropriate branch(es). Another method is to contact a server (puppet, etc) that does this.
If the user doing the push ([email protected]
) can own the files, an even simpler method is to run git checkout
in the hook, but with an alternate work-tree that has no other connection with the --bare
repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With