mo-7iq
Last Updated: February 25, 2016
·
14.3K
· jwebcat

Deploy your project with git to a bare repo

I have seen a lot of people using git to deploy their websites to a non-bare repo and using

$ git config receive.denycurrentbranch ignore

this works fine as long as you don't really do any updates in the remote repo itself. It is really recommended not to work this way by pro git unless you realize what your doing as it really isn't how git is set up to work.

  • the method I use

  • I like this method because it uses a bare repo with a check out working tree, so that there is no .git folder in your working tree.

  • It's also good because you can make changes in the working tree, and also have multiple people working on the repo and git will function normally.

  • One thing to note is, if you want to make changes in the working tree of the remote repo you will have to either

-make a file in the root of your working tree called .git
with the contents.

gitdir: /path/to/your/repo.git

Which is nice because you don't have to export GIT_DIR every time
Or

$ export GIT_DIR=path/to/your/repo.git

then

$ export GIT_WORK_TREE=path/to/your/workingtree

Every time you want to make changes in the working tree because a bare repo technically isn't allowed to have a working tree.

If you use core.worktree option to set the worktree it will fail and git will tell you core.bare and core.worktree dont make sense.

For some reason if you export GIT_WORK_TREE=path/to/your/repo.git
git doesn't complain.

Enjoy.

5 Responses
Add your response

4661

@jwebcat
I realized just one thing, but maybe I'm wrong.
The method described above implies to get the bare repo and the website working tree on the same server, isn't it ?
If not, how could you set your post-receive hook to be able to push from the bare repo to the website one, laid out on a different server ?
Any idea ?

over 1 year ago ·
4663
over 1 year ago ·
4664

@eviweb you are correct both the GITDIR and the GITWORK_TREE are on the same server. I dont know why you would want to have them on different servers?

Each clone of the GIT repo is essentially a remote working tree. So your local repo is a mirror of your remote working tree after you git pull and git push etc.

over 1 year ago ·
4665

@eviweb this is also good. He is using a bare repo as well. I like this method, however, if you're stuck with a jailshell on a shared hosting no sudo no dice if you know what I mean.

over 1 year ago ·
4668

@jwebcat

Both GIT_DIR and GIT_WORK_DIR are on different servers, simply because for now, I have got a server dedicated to the development part which hosts the bare shared repo and a public production one which hosts websites.

In that case I can clone the dev bare to a prod bare, but it adds a layer of complexity for no real gain.

The question was essentially for my own culture ;)

I will give a look anyway

over 1 year ago ·