11

First, the big picture: I'm trying to write a git post-receive script for a Redmine / Gitolite server I'm running. As per various recommendations, I'm creating a bare and local repository for Redmine to read from, and I'm setting up a post-receive script on Gitolite to push changes into the Redmine repo.

However, I'm very noobish with Git, so I'm unable to even do a simple task here >_<. I think if I figure this out, I should be able to write the above script. After setting up my test repo, I've created two repos as a test.

(The "Central Repo" is a Gitolite repository at git@localhost:testing)

cd /tmp
mkdir /tmp/test
$ git clone git@localhost:testing
$ git clone git@localhost:testing testing2
$ git clone git@localhost:testing --bare

Now when I run ls:

$ ls
testing  testing2  testing.git

Now, I change the test file inside of the testing2, and then push the changes to the central repo.

$ cd testing2
$ echo 'testline' >> test && git commit --allow-empty-message -a -m '' && git push 

As expected, if I run "git pull" on the "testing" folder, everything works as expected.

$ cd testing
$ git pull
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From localhost:testing
   3242dba..a1ca5ba  master     -> origin/master
Updating 3242dba..a1ca5ba
Fast-forward
 test |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
$ diff ./test ../testing2/test
$

As shown with the last "diff", the "testing" directory and "testing2" directory work exactly as expected. The "git pull" command synchronizes the two directories.

However, if I cd into testing.git (aka: the bare repo), a git fetch / git reset --soft fails to update the bare repo to the latest version.

$ ls
branches  config  description  HEAD  hooks  info  objects  packed-refs  refs
$ git fetch
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From localhost:testing
 * branch            HEAD       -> FETCH_HEAD
$ git reset --soft
$ cd ..
$ git clone ./testing.git testing3
Cloning into testing3...
done.
$ cd testing3
$ diff test ../testing2/test
5a6
> testline

As you can see from the last example, the bare repository failed to get updated, and there is somehow a difference between the two files. What did I do wrong?

Thanks in advance

Dragontamer5788
  • 1,957
  • 1
  • 12
  • 20

1 Answers1

27

Your fetch hasn't updated the master branch, only FETCH_HEAD (see "What does FETCH_HEAD in Git mean?").

As mentioned in "how do I pull to a bare repository?", you should do a:

git fetch origin master:master

Or, for all the branches:

git fetch origin +refs/heads/*:refs/heads/*

Colin D Bennett added:

If you want to fetch these on a regular basis, you should consider:

git config remote.origin.fetch +refs/heads/*:refs/heads/*

which will allow you to type git fetch to sync your branches with the remote.
Note that this make sense only in a bare repository where local branches are not supposed to be edited.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. A lot of issues seem to stem from my lack of understanding of branching... so I'll be sure to read up on it. – Dragontamer5788 May 23 '12 at 05:01
  • 6
    If you want to fetch these on a regular basis, you should consider: ``git config remote.origin.fetch +refs/heads/*:refs/heads/*``, which will allow you to type ``git fetch`` to sync your branches with the remote. Note that this make sense only in a bare repository where local branches are not supposed to be edited. – vaab May 05 '13 at 10:33