Skip to contentSkip to conversation

Getting git to help my memory

DISCUSSION Evan Driscoll 4 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I have a somewhat unusual question. I often forget to push after committing, and a few times this has come back to bite me. (One time I didn't even really realize for a couple months because I was working on other stuff, so unraveling the conflicts was "fun".)

Is there a way I can get git to print a "don't forget to push!" reminder after it commits?

The best way I can think of is to put a post-commit hook in there. I haven't tried it but I'd assume it would work, but would have to be on a per-repository basis instead of global.

(I use git mostly for just my own projects, and almost always mostly in sort of a centralized setup: I've got one bare *the* repository that I clone, and push to and pull from that rather than between the copies. For a variety of reasons, I'm pretty sure that model wouldn't work super well for me.)

Thanks,
Evan

#1 lore raw

Excerpts from Evan Driscoll's message of Tue Jul 05 17:34:18 -0400 2011:

Hi Evan,

Quoted 3 lines

The best way I can think of is to put a post-commit hook in there. I haven't tried it but I'd assume it would work, but would have to be on a per-repository basis instead of global.

I use this script as a post-commit hook in a few places...

--snip--
#!/bin/bash

echo -e "\e[32;01m"
echo "Don't forget to \git push\ this..."
echo -e "\e[0m"
--snip--

HTH.
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

#2 lore raw
In reply to Evan Driscoll
Quoted 11 lines · Evan Driscoll

I have a somewhat unusual question. I often forget to push after committing, and a few times this has come back to bite me. (One time I didn't even really realize for a couple months because I was working on other stuff, so unraveling the conflicts was "fun".)

Is there a way I can get git to print a "don't forget to push!" reminder after it commits?

The best way I can think of is to put a post-commit hook in there. I haven't tried it but I'd assume it would work, but would have to be on a per-repository basis instead of global.

Yes, I just tried this. Here is the output (from adding a file in the test branch):

---

$ git commit 
Don't forget to push!
[test ceabc34] adding test.txt.
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
---

The output is a bit hidden here. Maybe coloring would help here a bit.

Is it really intentional that post-commit is called *before* the informational output here?

I have no idea on how to automatically add the hooks to all the repositories - AFAIK git clone will not copy these.

Paŭlo

#3 lore raw
In reply to Evan Driscoll
Quoted 4 lines · Evan Driscoll

I have a somewhat unusual question. I often forget to push after committing, and a few times this has come back to bite me. (One time I didn't even really realize for a couple months because I was working on other stuff, so unraveling the conflicts was "fun".)

I have a cron job that sends me a mail with the list of "unpushed" repositaries on my account every nights (it also runs "git fsck", "git gc", and writes some .keep files to prevent "git gc" from repacking large packs and be friendly with backups and unison).

It's not really cleaned up, and may well work just for me, but in case you're interested, the scripts are attached:

* git-gc-fsck.sh is the script itself

* git-foreach is a home-made git command to manage a set of unrelated repositories. Essentially, one can

git foreach update => run some "find" commands in your $HOME to find
repositories.

git foreach do blah => run command blah in each repository.

#! /bin/sh

status=0
subject=""
[email protected]
body=/tmp/git-gc-fsck.$$

diff=$(git-foreach update)

if [ "$diff" != "" ]; then

    (
	echo "Git repository list changed:"
	echo "$diff"
	echo
    ) >> "$body"
    subject="$subject change"

fi

unpushed=$(git foreach --quiet do sh -c 'u=$(git rev-parse @{upstream} 2>/dev/null); if [ $? = 0 ]; then

    graph=$(git log --graph --oneline $u..);
    if [ "$graph" != "" ]; then
        pwd
        echo "$graph" | sed "s/^/    /"
        echo
    fi
    graph=""

fi')

if [ "$unpushed" != "" ]; then

    (
	echo "Some Git repositories have unpushed content:"
	echo "$unpushed"
	echo
    ) >> "$body"
    subject="$subject unpushed"

fi

failed_fsck=$(git-foreach do git fsck 2>&1)
fsck_status=$?

echo "$failed_fsck"

if [ "$fsck_status" != 0 ]; then

    subject="FSCK $subject"
    status=1
    (
	echo "Some Git repositories FAILED to fsck:"
	echo "$failed_fsck"
	echo
    ) >> "$body"

elif git-foreach do git keep-pack --size +10M && \
git-foreach do git gc > /dev/null; then
echo "git gc succeeded"
else
echo "git gc failed, fsck succeeded. This is VERY strange ..." subject="GC $subject"
status=1
fi

if [ "$subject" != "" ]; then

    mail -s "Git cron: $subject" "$email" < "$body"
    echo "Email sent to $email : $subject"
    cat "$body"
    rm -f "$body"

fi

exit "$status"

BTW, if you really always want to push after commit, you can as well have a post-commit-hook that does the push for you. But you lose part of the power of Git by doing so (you can't rebase -i before pushing for example).

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/