tags:

views:

121

answers:

2

Hi!

I have a repro in which I want to push changes. I want to sync two repositories: ./pages.git into ./pages. My git setup on my development machine pushes into pages.git. But the web-application works with ./pages.

git clone pages.git pages
fatal: destination path 'pages' already exists and is not an empty directory.

Well now I delete the pages directory and git clone works. But that's not the clean solution, isn't it?

Is there any way to do that without having to delete the pages directory manually? I'd like to automate that process so that git automatically performs the actions whenever I push.

Best, Marius

+3  A: 

Why not just create a post-receive hook for the pages.git repository that will do a git pull from within the pages repository to pull over the changes? git clone is designed to be run only once per resulting clone (hence why it complains until you delete the previous clone), whereas git pull is designed to be run repeatedly whenever you want to update a repo with changes from another.

I have a hook setup for something essentially the same as this with a particular repository, here's the gist of it:

cd /var/repos/path_to_mirror || exit
unset GIT_DIR
git pull origin master
  • In this case, path_to_mirror is the equivalent of pages in your situation.
  • This script would be in the pages.git/.git/hooks/post-receive file.
Amber
I think this won't work. As he pushes to pages.git from local repo - not commits there.
Marcin Gil
That's why it needs to be a `post-receive` hook. (Executed on the remote repository - in this case `pages.git` - after items have been pushed to it.)
Amber
A: 

In my understanding you're working on local copy, push to pages.git and have a copy for webapp?

If so, you can use post-receive hook on pages.git that will call git pull on pages or make a simple copy to pages.

Post-receive hook works on remote repo after push from local one. It is executed after all refs have been updated due to push.

Marcin Gil