-1

Is there a way to execute couple of git commands when I git push to master? What I'm having in mind is, once i did a git push for grunt to execute:

git checkout gh-pages
git merge master
git checkout master
Gilad Peleg
  • 2,010
  • 16
  • 29
Adonis K. Kakoulidis
  • 4,951
  • 6
  • 34
  • 43

2 Answers2

1

Why do you want to use Grunt to execute these commands? I think a normal shell script would suffice. Assuming you are on Linux, create an executable file called post-receive in the .git/hooks subdirectory, with the following contents:

#!/bin/sh
export GIT_WORK_TREE=$GIT_DIR/..
git checkout gh-pages
git merge master
git checkout master

For more information search this page for "post-receive hook".

Michael Herrmann
  • 4,832
  • 3
  • 38
  • 53
0

You can do that in a post-receive hook, which would:

  • go to a non-bare repo (meaning you need 2 repos on the server side: one bare, one non-bare)
  • git pull from the same bare repo you just pushed to
  • checkout, merge, checkout

You have an example in "how do I deploy multiple branches to different directories via git push?", but you need to complete that script an unset GIT_DIR, to be sure git takes into account the right non-bare repo after the cd /path/to/non/bar/repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250