On Sat, Oct 20, 2012 at 12:48:33AM -0300, Gabriel Lau wrote:

> Thanks for your reply Konstantin. I did what you said and it worked as I
> wanted. Now I can switch between the branchs when necessary.
> I just have one more question: whenever I have to checkout between branchs,
> I have to input the commands that you showed me. Is there any way to
> automate this process?
>  $ export GIT_WORK_TREE=/path/to/that/directory
>  $ export GIT_DIR=/path/to/your/bare/repo
>  $ cd $GIT_WORK_TREE
>  $ git checkout experiment
> For example: After logging on the server and go to the directory of my bare
> repository, I can just checkout the branch without having to inform the
> WORK_TREE on each process?
> $ git checkout experiment

What's the problem with putting the sequence of commands cited above to
a script and then running it?  That's what scripts are for, after all.

Note that the the need for setting up those environment variables is
precisely due to the fact you're working with a bare repo.
With regular repos, there's never a question about where things are
located: a repo *is* a work tree with its very own "Git dir" located in
a well-known place -- the directory named ".git" in the work tree.

Now think how `git checkout <branch>` works.  To check out a branch, it
has to go to the Git directory to find the branch and be able to get
hold on its objects.  And then in has to update the work tree, which is
located where?  Hence the need to tell Git where the things are located.

Note again that you did not tell us much details about your setup even
though this was politely requested.  It might turn out your use case
could be better served by means other than working with detached work
trees, but we can't guess *that* good.

Detached work trees are okay for one-off emergency fixups or scripts for
automatic deployment (in the first case it's okay to take extra pain
to set things up in exchange for little intrusion, in the second case
the complexity is only to be implemented once).  So either automate the
process (by means of writing a script or scripts) or provide much more
details on what you want to achieve and may be we'll be able to figure
out a better workflow.

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to