Pergunta

I am using webfaction for my web deployment.

I have a Django app at: webapps/django_app/project_name/

I have a Git repo at: webapps/git_app/repos/my_repo.git

my_repo.git is a bare repository. It is not a working directory.

whenever I push from my local development computer to the remote (webfaction --> my_repo.git), I want my django_app to get the pushed code.

I followed this post which works fine. But no explanation of how this works is given.

I have added these two lines in post_recieve hook in my_repo.git.

#!/bin/sh
GIT_WORK_TREE=/home/username/webapps/django/myproject git checkout -f 
GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard

what does this two lines actually do?

Moreover, my Djangoapp folder is not a git repo. still whenever push is made to my_repo.git, Djangoapp gets updated. so how does it work?

Foi útil?

Solução

When you are managing files locally with .git, you typically have two things:

  • Your git repository, which is contained in the .git directory, and
  • Your work tree, which is the set of files you are actually editing.

By default, the repository is a subdirectory of the work tree, but this is not a requirement. Setting the GIT_WORK_TREE environment variable directs git to use a different location for your checkout out files.

So the first line...

GIT_WORK_TREE=/home/username/webapps/django/myproject git checkout -f 

...is asking git to check out the HEAD of the repository into /home/username/webapps/django/myproject.

The second line...

GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard

...makes sure that /home/username/webapps/django/myproject does not have any local changes. reset --hard discards any changes to files that are tracked by git. By "local changes" I mean any changes that you or someone else has made to files in this directory; ideally, there won't be any, but if there were some there, reset -f makes sure that the modified files are overwritten with the version of the file stored in the repository.

For more details on any of the commands listed here, try running git <command> --help for the man page, or see The Git Book.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top