Git Hook - task failed

For the task (details below). I made a copy of the post-update.sample file and name as post-update.
The post-update file content (details below). I executed manually to see if it will create a tag and it did. Then checkout master branch (git checkout master) and merge the feature branch (git merge feature) at the end I push all my changes (git push --all).

I get the below error and I have no idea why.

  • seems like ‘post-update’ hook is not working
    FAILED git_hooks.py::test_git_hooks - AssertionError: - seems like 'post-upda…

Task details

The Nautilus application development team was working on a git repository /opt/blog.git which is cloned under /usr/src/kodekloudrepos directory present on Storage server in Stratos DC. The team want to setup a hook on this repository, please find below more details:

Merge the feature branch into the master branch`, but before pushing your changes complete below point.

Create a post-update hook in this git repository so that whenever any changes are pushed to the master branch, it creates a release tag with name release-2023-06-15, where 2023-06-15 is supposed to be the current date. For example if today is 20th June, 2023 then the release tag must be release-2023-06-20. Make sure you test the hook at least once and create a release tag for today’s release.

Finally remember to push your changes.

post-update (file content)

current_date=date +"%Y-%m-%d"
release_name=“release-$current_date”

exec git tag $release_name

Its anybody else try to complete the task “Git Hook” or I’m the only one?
I will be very happy if anybody could point to right direction.

Hi @tsanghan
Thank you for your respond. I set up my git hooks on the cloned repo /usr/src/kodekloudrepos and I should set it up in the bare repo /opt/blog.git.

All working now

Thank you for your help

1 Like

@maciejws can you share your whole post-update file content?

I am not able to understand how it did work for you, I am trying but I am not able to complete the task

Done, Thank you so much

Hello ,

I have this hook set up in remote repo location. /opt/ecommerce.git/

cat post-update
#!/bin/bash

Get the current date

DATE=$(date +“%Y-%m-%d”)

Create the release tag

exec git tag “release-$DATE”
exec git push origin “release-$DATE”

but still i dont see push triggering commit and creating tag.
I am seeing this error message.
seems like release tag was not created from the ‘master’ branch
what did you do it differently ?

  • cd to bare repo

/opt/cluster.git/hooks

  • Then create the post-update hook

#!/bin/bash

#Get the current date

date=$(date +“%Y-%m-%d”)

#Create a release tag with the current date

git tag release-$date

  • Once the tag is created go to cloned repo

Git checkout master

Git merge feature

You will see the tag has been release with current date.

3 Likes

Thank you , that worked .
so we need to create a tag first and then do the merge and push.

2 Likes

Yes. That’s great I was able to help!

Thank you!!! create tag when I do git pull after merge and push

Thank you,it worked for me!

Good day people,

This question has me CONFUSED…lol.

The Nautilus application development team was working 
on a git repository /opt/media.git which is cloned under 
/usr/src/kodekloudrepos directory present on Storage server 
in Stratos DC. The team want to setup a hook on this repository, 
please find below more details:



Merge the feature branch into the master branch`, but before 
pushing your changes complete below point.

Create a post-update hook in this git repository so that whenever 
any changes are pushed to the master branch, it creates a release 
tag with name release-2023-06-15, where 2023-06-15 is supposed to 
be the current date. For example if today is 20th June, 2023 then the 
release tag must be release-2023-06-20. Make sure you test the hook 
at least once and create a release tag for today's release.

Finally remember to push your changes.

I did the following and even confirmed that the tag exists in the bare repo. I don’t know why I keep getting marked wrong. Please I need help.

[root@ststor01 hooks]# chmod +x post-update
[root@ststor01 hooks]# cd /usr/src/kodekloudrepos/media/
[root@ststor01 media]# git branch
* feature
  master
[root@ststor01 media]# git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
[root@ststor01 media]# git merge origin master
merge: origin - not something we can merge
[root@ststor01 media]# git merge feature
Updating 241846a..ed2b928
Fast-forward
 feature.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 feature.txt
[root@ststor01 media]# git push origin master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Creating tag release-2025-08-10
To /opt/media.git
   241846a..ed2b928  master -> master
[root@ststor01 media]# 

content of my post-update file, if that helps:

[root@ststor01 media]# cat /opt/media.git/hooks/post-update
#!/usr/bin/sh

# Arguments to post-update
DATE=$(date +%F)        # YYYY-MM-DD
GIT_DIR=$(pwd)

for ref in "$@"
do
    if [ "$ref" = "refs/heads/master" ]; then
        echo "Creating tag release-$DATE"
        git --git-dir="$GIT_DIR" tag -f "release-$DATE" master
    fi
done

Big thanks in anticipation.

Okay, so I think the “-f” flag in the hook was the problem.

I think the system checks by trying to push and verifying that the tag already exists.

I took that out and it seems to work fine.

This legit stressed me out. :slight_smile:

Thought I’d post this (instead of straight-up deleting for anyone that might be adding the “-f” flag. lol)

In essence, it makes my loops all useless, so you don’t need to loop or check if it already exists. lol

Thank you, worked for me after 4 times try to complated this tasks

I tried multiple time not working,


ssh natasha@ststor01

cd /opt/apps.git
git remote add origin /opt/apps.git

sudo chown -R natasha:natasha /opt/apps.git
sudo chmod -R 775 /opt/apps.git
ls -ld /opt/apps.git

cd /opt/apps.git/hooks
sudo vi post-update

#!/bin/bash
date=$(date +%Y-%m-%d)
git tag "release-$date"
git push origin "release-$date"

sudo chmod +x post-update
cd /usr/src/kodekloudrepos/apps/

sudo chown -R natasha:natasha /usr/src/kodekloudrepos/apps/
sudo chmod -R 775 /usr/src/kodekloudrepos/apps/

git branch

git config --global user.name “Natasha”
git config --global user.email “[email protected]

git add .
git commit -m “Committing before switching to master”
git checkout master
git merge feature

git status
git log --oneline

git push origin master

cd /opt/apps.git/
git tag #release-2025-09-03