Information Technology Reference
In-Depth Information
# command issued in johns-repo
$ git remote add origin ../public-repo
Create three commits in
johns-repo
with:
# command issued in johns-repo
$ git simple-commit one two three
and push them to public-repo with
$ git push origin master
.
If you now list the files in
public-repo
with
$ ls
, you will notice that its
working directory contains the
one.txt
,
two.txt
, and
three.txt
files. This
proves that the push operation transferred the latest state of
johns-repo
to
public-repo
.
How It Works
Pushing to a non-bare remote repository causes problems because of the working dir-
ectory. Suppose you and you colleague work in the master branch and you both create
a file named
lorem.txt
. If you commit your file and push it to your colleagues re-
pository what should happen to his working directory? Should a checkout be per-
formed? If so your friend can lose his work done in
lorem.txt
.
The first step is to allow a push in such a way that the remote branch is updated. It is
done with:
$ git config receive.denyCurrentBranch ignore
This command allows you to push to a remote repository. The push will upload ne-
cessary objects from your repository to a remote database and then it will update the re-
mote branch you are pushing to. The working directory of the remote repository will
not be affected.
To perform a checkout in the remote repository we have to configure the path to the
working directory. It is done with:
$ git config core.worktree ../
The last step is to force a checkout when someone pushes to
public-repo
. This
is done with
post-update
hook. To use a hook you have to create a shell script