Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Initial commit!

  • Loading branch information...
commit 8fce90ecb5230878d551e8dfda8400793927cf50 0 parents
@appden authored
Showing with 93 additions and 0 deletions.
  1. +27 −0
  2. +22 −0 gits
  3. +44 −0 hooks/update
@@ -0,0 +1,27 @@
+More to come.
+All code in this repository is subject to the terms of the zlib license.
+Copyright (c) 2011 Scott Kyle
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source
+ distribution.
22 gits
@@ -0,0 +1,22 @@
+# This simple script will stash changes in git while running a command.
+# If you use bash tab completion add this line to your ~/.bash_profile:
+# complete -o default -o nospace -F _git gits
+# Bonus for those of you using GitX:
+# complete -o default -o nospace -F _gitk gitx
+# by Scott Kyle (appden)
+if git diff --ignore-submodules=all --no-ext-diff --quiet --exit-code HEAD; then
+ # if the work tree and index are clean just run the command
+ git $@
+ # otherwise stash, run the command, then pop the stash
+ git stash && git $@ && git stash pop
+# exit with the last command's exit code
+exit $?
44 hooks/update
@@ -0,0 +1,44 @@
+# This git update hook will refuse unnecessary merge commits caused by pulling
+# from being pushed to a shared repository. These commits make following the
+# history of a project difficult and are always avoidable with rebasing.
+# by Scott Kyle (appden)
+# if this is not run as a hook, you may have messed up
+if [ -z "$GIT_DIR" -o -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
+ echo "Usage: GIT_DIR=<path> $0 <ref> <oldrev> <newrev>" >&2
+ exit 1
+# if the new revision is all 0's then it's a commit to delete a ref
+# also check if the new revision is not a commit or is not a fast forward
+if [ "$newrev" = "$zero" ] || [ $(git cat-file -t $newrev) != "commit" ] || [ $(git merge-base $oldrev $newrev) != "$oldrev" ]; then
+ exit 0
+# loop through merges in the push only following first parents
+for merge in $(git rev-list --first-parent --merges $oldrev..$newrev); do
orefalo added a note

this line is giving me the following error:

fatal: ambiguous argument '4fe80ec7ad2205d6ca3ad2a3238b680308cf7830..7c98319b60babfea2ffebc357caf': unknown revision or path not in the   working tree.
Use '--' to separate paths from revisions
@appden Owner
appden added a note
orefalo added a note

I got it, no worries. If I recall it was the version of git which was the problem.
Using git 1.7.7 fixed the issue


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ # lazily create the revision list of this branch prior to the push
+ [ -z "$revlist" ] && revlist=$(git rev-list $oldrev)
+ # check if the second parent of the merge is already in this branch
+ if grep -q $(git rev-parse $merge^2) <<< "$revlist"; then
+ cat >&2 <<-EOF
+ *** Push to ${refname#refs/heads/} rejected because of merge commit caused by pulling
+ *** To fix: git pull --rebase
+ ***
+ *** Permanent fix: git config [--global] branch.autosetuprebase always
+ *** Then for existing branches: git config branch.<name>.rebase true
+ exit 1
+ fi
+# clean history successfully preserved!
+exit 0

0 comments on commit 8fce90e

Please sign in to comment.
Something went wrong with that request. Please try again.