1

Here's the setup I'm using at the moment:

HOOK 1 We will use a post-update hook on our HUB repository. So, when a push is made to the HUB by any other clone, the HOOK get’s activated and it will, according to the HEAD pointer placement, access the corresponded WORKING DIRECTORY, either on development or master, and it will from there, either: pull from hub into development branch OR pull from hub into master branch.

On ~/private/repos/projectname_hub.git/hooks create a file named post-update pico post-update and place the following inside:

#!/bin/sh

echo
echo "**** Pulling changes into Dev [Hub's post-update hook]"
echo

case " $1 " in
*'refs/heads/dev'*)
        cd /home/user/www/dev/ || exit
        unset GIT_DIR
        git pull hub dev
        echo
        echo "Dev was pulled"
        echo
        ;;
esac

case " $1 " in
*'refs/heads/master'*)
        cd /home/user/www/www/ || exit
        unset GIT_DIR
        git pull hub master
        echo
        echo "Master was pulled"
        echo
        ;;
esac

exec git-update-server-info

HOOK 2 To prevent history conflicts, if we commit directly on production server for some reason, each time a prime master commit occurs, we PUSH those committed changes to the HUB.

On ~/www/www/.git/hooks create a file named post-commit pico post-commit

#!/bin/sh

echo
echo "**** pushing changes to Hub [Prime's post-commit hook]"
echo

git push hub

With the setup above, sometimes, I cannot precise when, we may have pushed things to the master it says "Everything is up to date" but it isn't.

Obviously all files where added and committed.

So, and after some help, we end up finding that the issue is, on the Hook setup.

I've been told to, instead of using on the post-update hook: git pull hub master I could use:

git fetch hub && git reset --hard hub/master

My question is: Can anyone please provide the necessary explanation why does the git pull hub dev works, and git pull hub master sometimes doesn't, and how will this line help me out ?

Yes, I'm quite new on git usage, and I wish not to blind copy paste the above without at least understand. If someone could drop a few lines, it would be really appreciated.

Update: When I do git branch -a this is what I get:

* master
  remotes/hub/dev
  remotes/hub/master

Thanks in advance.

MEM
  • 30,529
  • 42
  • 121
  • 191

1 Answers1

1
git fetch hub && git reset --hard hub/master

This is an alternative only if you don't develop at all on /home/user/www/www/: it reset master HEAD of www/www to the one fetched from hub.
But that is not the case for you, since you have a post-commit on www/www to push back.

we may have pushed things to the master it says "Everything is up to date" but it isn't.

It is usually because of a DETACHED HEAD situation (where you commit in a branch without HEAD). Check git branch -a when that happens, and make sure you are in a branch.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks for your detailed explanation. `git branch -a` on the remote under `www/www` ? Plus, if you where to change this hook, would you change something in order to avoid that ? I'm asking this because, it happen again. I made changes, it says: `everything is up to date` but I always need to ssh the remove server and manually do: `git pull hub master` on `www/www` directory. :( – MEM Nov 27 '12 at 16:16
  • I've updated my question with the result of the command `git branch -a` on the remote server. – MEM Nov 27 '12 at 16:27
  • 1
    @MEM the '`*`' means that you are not in a detached head, but you could add that line to your hook. On the instances where it doesn't work, you can have a look at the hook output, and see if the '`*`' was there or not, when the push mentioned that "`Everything is up to date`" – VonC Nov 27 '12 at 16:33
  • perhaps something should be clear, not sure if it's important. But, that message, as far as I recall, never occurs when I do a push. After I do it, I see that nothing have changed as it should, and then, I do a `git status` on the remote www/www/ working dir, and it's there, where I get "`Everything is up to date`". By "that line" what line are you referring to ? – MEM Nov 27 '12 at 17:34
  • 1
    @MEM "that line" = `git branch -a`in your hook. However, if you see it only on `git status` (and not `git push`), this is a different issue (ignored files?), and not necessarily related to a detached HEAD. – VonC Nov 27 '12 at 17:56
  • Exactly. @VonC I tried to reproduce the error, but I couldn't and everything works fine now. If this happens again, what command should I issue to understand what's going on and try to fix it ? If, despite the details posted here, there's no "one answers fits all", then, perhaps my best option is to complain on the right moment that happen and ask instructions about HOW to discover what's going on, no? I mean I do "git status". If I do it on DEV I get some files added that are not tracked by git (not a big issue I believe). If I do it on master I get "`Everything is up to date`" message. – MEM Nov 27 '12 at 18:11
  • you made me understand a couple of things so I mark your question as useful. The answer however, is still to be discovered. :s – MEM Nov 27 '12 at 18:13
  • Errors on my previous post: - First: "answer" instead of "question. Second: "real answer" instead of "answer". Please note that I've not edited some "ignored files" or gitignore mentioned files on those cases. Regular repository files where edited. – MEM Nov 27 '12 at 18:22
  • @MEM ok. Updating your question (or making a new question) in the exact context where this "false" up-to(date state occurs will certainly be helpful. – VonC Nov 27 '12 at 18:27
  • I will do that. Neither the less. Thanks a lot for your time and patience. – MEM Nov 27 '12 at 18:30