Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use a git bare repository for website deployment?

Tags:

git

I'm starting to deploy a few website plugins via git.

I've been through a number of tutorials on the web and all of them recommend creating a bare remote repository on the web server with a post-update hook to checkout into the DocumentRoot directory. I've gotten this all working without too many issues.

Why are we separating the respository from the working directory? What's wrong with just using the DocumentRoot directory as the repository and then using htaccess to prevent public access to any .git content?

like image 800
Jonathan Avatar asked Nov 26 '13 00:11

Jonathan


People also ask

What is the point of a bare repository?

Repositories in Git are a snapshot of the folder in which you are working on your project. You can track the progress and changes made to the project by making commits and also revert changes if not satisfactory.

Why do I need a git repository?

A Git repository tracks and saves the history of all changes made to the files in a Git project. It saves this data in a directory called . git , also known as the repository folder. Git uses a version control system to track all changes made to the project and save them in the repository.

What is git bare and git non bare repository use cases?

A bare repository is one that contains nothing but the . git folder; in other words, it has the index but lacks the actual working files. A non-bare repository is what you're used to working with, which includes both the git index and the checked out copy of working files.

Can git be used for deployment?

Git deployment If you want to share changes with others, you run git push . Since only changesets are uploaded or pulled, these operations are very fast. However, many people don't know that they can deploy with Git just as easily.


1 Answers

Actually the security risks inherent in a poorly configured htaccess are a good reason by themselves, but the main reason is that by default, you can't push to the checked-out branch of a non-bare repo. (It can be enabled, but then requires a git reset --hard to update the work tree, and is no simpler than having a separate deployment directory.)

like image 106
Fred Foo Avatar answered Sep 20 '22 18:09

Fred Foo