1đź‘Ť
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.