2

We have recently migrated our git repository from Gitlab to Bitbucket.

Now i want to make sure that the team needs to commit to both repositories until Gitlab gets decommissioned.

By just telling them, it will not be sufficient as one might forget to push to the bitbucket which has the new repository and it might lead to production issues.

What i want to do is to have some kind of message like "please push to the BitBucket repository as well to avoid the conflicts" displayed on user's machine when he tried to make any commit in Gitlab(which is the current repo) so that he is reminded of it every time when he commits to Gitlab.

Can someone please tell me how to achieve this with the help of git hooks.

Abhishek Somani
  • 473
  • 2
  • 6
  • 17
  • 1
    You might want to check your verbage. Maybe change “check in” to “push” – evolutionxbox Apr 24 '18 at 19:10
  • sorry i did not understand that..what i want to do is when somebody runs git commit -m "commit-message" and hit enter, he shud see "please commit in the bitbucket also" on his screen – Abhishek Somani Apr 24 '18 at 19:17
  • 1
    Remember you don’t commit to a remote like bitbucket. Check-in is an svn term so I was recommending you use the standard git terminology – evolutionxbox Apr 24 '18 at 19:20
  • 1
    Why remind your devs to perform a manual task that can be automated it? I suggest the following alternative: ask your devs to set up their `origin` remote to push to both Bitbucket and Gitlab; see https://stackoverflow.com/a/14290145/2541573 – jub0bs Apr 24 '18 at 21:11

1 Answers1

1

As you mentioned you need to set the pre-receive hook

pre-receive hook

#!/bin/sh

# Output colors
red='\033[0;31m';
green='\033[0;32m';
yellow='\033[0;33m';
default='\033[0;m';

# personal touch :-)
echo "${red}"
echo "                                         "
echo "                   |ZZzzz                "
echo "                   |                     "
echo "                   |                     "
echo "      |ZZzzz      /^\            |ZZzzz  "
echo "      |          |~~~|           |       "
echo "      |        |-     -|        / \      "
echo "     /^\       |[]+    |       |^^^|     "
echo "  |^^^^^^^|    |    +[]|       |   |     "
echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
echo "  |       |  []   /^\   []   |+[]+   |   "
echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
echo "  |[]+    |      || ||       |[]+    |   "
echo "  |_______|------------------|_______|   "
echo "                                         "
echo "                                         "
echo "  ${green}                               "
echo "  You have to commit your code   " 
echo "  To Gitlab as well !!!!!        "
echo "                                 "
echo "  ${red}                         "
echo "  P.S: Your code is bad.         "
echo "       Do not ever commit again  "
echo "                                 "
echo "                                 "
echo "${default}"

exit 0;

  • You can also add client-side hooks for this purpose.
  • In Bitbucket hooks are located under <Bitbucket home>/data
  • For gitlab you can read here how to set up hooks and where they are located
    https://docs.gitlab.com/ee/administration/custom_hooks.html

  • You can also use Plugins to specify where your hooks script are located but those plugins are not free anymore.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    i have checked this earlier that docs.gitlab.com is not working.A hook has to be integrated within gitlab to enforce this commit message. – Abhishek Somani Apr 24 '18 at 19:29