Run git command inside bash script

I am writing a gitosis post-push hook for a central repository

which retrieves updates from the central repository to test the environment

nano /var/git/repositories/holding.git/hooks/post-update

  #!/bin/bash cd /var/vh/holding; git reset --hard; git checkout testing; git pull; 

here is what i get after clicking on my client (VM development)

 # blah ... Counting objects: 57, done. Compressing objects: 100% (24/24), done. Writing objects: 100% (30/30), 3.42 KiB, done. Total 30 (delta 18), reused 0 (delta 0) fatal: Not a git repository: '.' fatal: Not a git repository: '.' fatal: Not a git repository: '.' fatal: Not a git repository: '.' To git@cheby.ru :holding.git 233b5a2..0f46cd8 testing -> testing 

Obviously, my attempt to tell git where it should do pull failed.

What is the correct way to run the git command for the specified working copy in a bash script?

+5
source share
2 answers

As mentioned here or there , you could precede all your git commands with:

  env -i 

to ensure that there is no side effect, for example, with the GIT_DIR environment variable that could have been set earlier.
( env -i or simply: unset GIT_DIR )

+5
source

Is /var/vh/holding a git repository? those. did you run git init on it, set up your remotes, set it to track your hold.git folder, etc.? Also, if you are not pulling with the same repo you are pushing to, you do not need reset and checkout .

0
source

Source: https://habr.com/ru/post/910954/


All Articles