1

While using git, we all have our code in our own repository, pushing to and pulling from a bare repository.

If I need parts of the newest code in a specific folder for later use by an automated script, what would be the best way to get the code from the personal repository to that specific folder? (Is there a "git way" of doing this?)

Thank you.

DAHNNY
  • 21
  • 4
  • Could you elaborate a bit more on a) how many bare repos (each person has their own or one shared?) and b) how the layout of that "specific folder" shall look like (e.g. each contributor has their own folder, or shall files of all contributors land in the same folder)? And c) who/what is going to use that "specific folder" for which purpose ("by an automated script" is quite vague)? – ojdo Sep 30 '21 at 08:16
  • a) one shared bare repo; b) all edits of the files shall land in the same directory; c) the code is being read by a BI-tool – DAHNNY Sep 30 '21 at 08:42
  • best practice on this site is to edit your original question, so that all upcoming readers get the best version without having to go through the comment thread (which are supposed to be only temporary, not vital part of the Q's and A's, although many questions look differently). – ojdo Sep 30 '21 at 13:20
  • Is there some reason you don't just create a (non-bare) repo at the desired location and issue pulls from the required source repo? – William Pursell Sep 30 '21 at 14:04
  • Yes ojdo, right. I'll do it that way next time. Anyways, as William mentioned, it's possible to just not use the bare repo. I'll answer my own question on how it worked. – DAHNNY Sep 30 '21 at 14:27

2 Answers2

1

Git only

If you only want to rely exclusively on Git features, a combination of a post-recive server-side hook combined with an external worktree at the location where your automated script expects to find the updated scripts.

Rough sketch:

  • Set up the worktree at the location on the server where your BI-tools want to read them.
  • Add a server-side hook that updates that worktree, roughly like shown in the worktree example:
    pushd ../worktree
    git checkout -f <main-or-other-branch-to-follow>
    popd
    

Github

If your bare git repo is actually hosted on Github or a local Gitlab instance, you might have the benefit of using Github Actions or Gitlab CI pipelines. For just this action, both mechanisms introduce much baggage, but scale much better to much more automation around your development, especially increased visibility (you see which actions were triggered by event).

ojdo
  • 8,280
  • 5
  • 37
  • 60
1

The solution to my problem: Not using a bare repository. I thought, that I have to use the bare repo to push etc. BUT...

As I learned, I can just create a normal repository with git init and after that execute the command:

git config --global receive.denyCurrentBranch updateInstead

This opens the repository up AND the repository will be able store all our changes at one place. Now just add it as remote and et voilà.

DAHNNY
  • 21
  • 4
  • 1
    Very nice self answer! Maybe add a link [to the official docs](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-receivedenyCurrentBranch). – ojdo Sep 30 '21 at 15:01