Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't I see files after push to Bare git repo

Tags:

git

github

ssh

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)
like image 568
The Atlantean Avatar asked Oct 01 '13 15:10

The Atlantean


2 Answers

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.

like image 197
Noufal Ibrahim Avatar answered Sep 23 '22 22:09

Noufal Ibrahim


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.

like image 21
torek Avatar answered Sep 24 '22 22:09

torek