I have a bare repo that receives only pushes. When such pushes are made, I’d like for those changes to be reflected by the bare repo to another location (not a clone, just a static location with no .git folder).
Is this possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Sure. In order to do some action whenever someone pushes, create a
post-receivehook. In order to get those changes from a bare repository into another directory (which is not a Git repository), you will need to create agit archiveand expand it in the location that you want to update.The
post-receivehook receives on standard input a list of all refs that have been updated by a push as well as their old and new values, in the following format (whereSPis a space character,<old-value>and<new-value>are revisions, and<ref-name>is the ref that was updated):If you’re only interested in mirroring
masterinto your destination directory, you’ll want to only execute your script if you see such a line.For example, something like this would probably work (untested, so test this out on a location you don’t care about before trusting it):
edit: Note that this has a fairly serious drawback; if you delete (or move) a file, this won’t delete that file in the destination directory. One potential solution would be to add an
rm -rf /path/to/expand/into; mkdir /path/to/expand/intobefore the archive line.