1

For example, when I push branch to GitLab or Bitbucket, I see such message:

Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for branch-name, visit:
remote:   https://gitlab.com/username/reponame/merge_requests/new?merge_request%5Bsource_branch%5D=branch-name
remote:
To gitlab.com:username/reponame.git
 * [new branch]      branch-name -> branch-name

Is there easy way to add such message for GitHub?

artem_russkikh
  • 437
  • 4
  • 14

3 Answers3

2

That message comes from the post-receive hook configured in the remote repository. It is part of the software running on the Git server.

Unless you can modify the code on the server (GitHub), no you cannot customize it.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
1

Here is workaround using bash script for git origin push remote.

Create file ~/.github-create-pr.sh containing :

#!/bin/bash
#
# ~/.github-create-pr.sh

IS_GITHUB=$(git remote -v | grep "origin.*(push)" | grep -c "github.com")

if [ $IS_GITHUB -ne 0 ]; then
  REPO_NAME=$(git remote -v | grep "origin.*(push)" | sed 's/.*:\(.*\)\.git.*/\1/g')
  BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
  echo ""
  echo "To create a merge request for $BRANCH_NAME, visit:"
  echo "https://github.com/$REPO_NAME/compare/$BRANCH_NAME?expand=1"
  echo ""
fi

And then

git push && sh ~/.github-create-pr.sh
artem_russkikh
  • 437
  • 4
  • 14
  • Very useful. I'm using gitlab and I apply this to create extra message, print merge request with destination branch: `echo " https://$server/$REPO_NAME/-/merge_requests/new?merge_request%5Bsource_branch%5D=$BRANCH_NAME&merge_request%5Btarget_branch%5D=dev"` – Do Minh Phong Feb 18 '21 at 16:52
-1

As @Jonathon Reinhart mentioned you have to add use hooks in order to achieve your request.

In GitHub you have to create WebHooks for this purpose.
Read here how to create hooks under your GitHub account.


How to add webhooks to GitHub

In GitHub:

1. Sign in, then select the related repository you own.
2. Click on "Settings" on the right panel.
3. Then click on "Webhooks" on the left panel.
4. Click on the "Add WebHook" Button.
5. Paste the copied URL in the URL form field.
6. Select "application/json" as the content type.
7. Select "Just the push event"
8. Leave the "Active" checkbox checked.
9. Click on "Add webhook" to save the webhook.

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Are these executed synchronously from the Git hook? And are they able to return a string that is actually returned to the pushing git client? – Jonathon Reinhart Apr 24 '18 at 11:33