Here's my current hook in a bare repo that lives in the company's server:
git push origin master
This hooks pushes to Assembla.
What i need is to push only one branch (master, ideally) when someone pushes changes to that branch on our server, and ignore pushes to other branches. Is it possible to select the branch from a bare repo and push only that branch to Assembla?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Outlook Object Model - Hooking to the Conversation
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
A post-receive hook gets its arguments from stdin, in the form
<oldrev> <newrev> <refname>
. Since these arguments are coming from stdin, not from a command line argument, you need to useread
instead of$1 $2 $3
.The post-receive hook can receive multiple branches at once (for example if someone does a
git push --all
), so we also need to wrap theread
in awhile
loop.A working snippet looks something like this:
The answer from @pauljz works fine for certain git hooks like
pre-push
, butpre-commit
does not have access to those variablesoldrev newrev refname
So I created this alternate version which works for pre-commit, or really and hook. This is a
pre-commit
hook that will run ahusky
script if we're NOT on themaster
branch.I hope that helps someone. You can easily modify for your needs, anything in between the
if
andfi
statements.The last parameter that a post-receive hook gets on stdin is what ref was changed, so we can use that to check if that value was "refs/heads/master." A bit of ruby similar to what I use in a post-receive hook:
Note that it gets a line for each ref that was pushed, so if you pushed more than just master, it will still work.
Stefan's answer didn't work for me, but this did:
I had written a PHP script for myself to do this functionality.
https://github.com/fotuzlab/githubdump-php
Host this file on your server, preferably repo root and define the url in github webhooks. Change 'allcommits' on line 8 with your branch name and add your code/function at line 18.
e.g.
Simple approach, in
git hook
writeSimple - more info on this great link hooking system