Skip to content

Commit cbfb883

Browse files
committed
Add pre-push hook to disable pushing to upstream
By default developers should not be able to push to upstream repo unless they manually remove this hook. This is to prevent accidental pushes.
1 parent 0a11329 commit cbfb883

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

git_hooks/pre-push

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
# An example hook script to verify what is about to be pushed. Called by "git
4+
# push" after it has checked the remote status, but before anything has been
5+
# pushed. If this script exits with a non-zero status nothing will be pushed.
6+
#
7+
# This hook is called with the following parameters:
8+
#
9+
# $1 -- Name of the remote to which the push is being done
10+
# $2 -- URL to which the push is being done
11+
#
12+
# If pushing without using a named remote those arguments will be equal.
13+
#
14+
# Information about the commits which are being pushed is supplied as lines to
15+
# the standard input in the form:
16+
#
17+
# <local ref> <local sha1> <remote ref> <remote sha1>
18+
#
19+
# This sample shows how to prevent push of commits where the log message starts
20+
# with "WIP" (work in progress).
21+
22+
remote="$1"
23+
url="$2"
24+
25+
forbidden="google"
26+
27+
if test "${url#*$forbidden}" != "$url"; then
28+
echo "Pushing to $forbidden is disabled by default. If you need to push to"
29+
echo "that repo please edit the pre-post git hook."
30+
exit 1
31+
fi
32+
33+
exit 0

0 commit comments

Comments
 (0)