Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5998591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:25:41+00:00 2026-05-23T00:25:41+00:00

I am making a git post-commit hook to post my commit messages to Twitter.

  • 0

I am making a git post-commit hook to post my commit messages to Twitter. I have set up the hook on the server, which means it only runs when I call git push.

To interface with git from python, I am using GitPython. In my code, I am using repo.head.commit.message to get the latest commit message. Which means if I push multiple commits, it only gets the last one.

This is what I have so far.

class GITHelper:
    "This class interacts with GIT for us"
    def __init__(self, path):
        repo = git.Repo(path)
        headcommit = repo.head.commit
        self.message = headcommit.message
        self.author = headcommit.author.name

How can I get all commits from a push? Or, how can I get the number of commits that were pushed?

repo.iter_commits('master', max_count=5) can get as many commits as I want, so if I knew how many commits there were, I could use that.

EDIT: I was testing, and when I run git push, it seems this hook gets the head from the last commit, not the one I just pushed. How do I make a post-commit hook that gets the messages from the commits I just pushed to the server?

EDIT 2: I am actually using the update hook, not the post-commit hook, is that the correct hook to use on the server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:25:42+00:00Added an answer on May 23, 2026 at 12:25 am

    The githooks docs say:

    The hook executes once for each ref to be updated, and takes three parameters:
      - the name of the ref being updated,
      - the old object name stored in the ref,
      - and the new objectname to be stored in the ref.
    

    So, check the arguments your script gets, you should also get the new ref, and then you can figure out the commits in between the old and new refs. If it were a shell script, you could do:

    git log --oneline $oldRef..$newRef
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been making a little toy web application in C# along the lines
I'm making a WinForms app with a ListView set to detail so that several
I've been doing a workflow of making a git repository on a remote central
Git is making me pull my hair out. I know how to create a
I'm tracking a Virtual PC virtual machine file (*.vmc) in git, and after making
I am making changes to some file in my local git repository and then
Git newbie here. I am probably making a simple mistake here, but I can't
Making echo of a question around the web: Is the syntax for svn:ignore patterns
When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
After making some changes in my models (eg. new field in a model and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.