I'm creating a custom sharedgitconfig file in one of the repositories of a project in bitbucket based on what I was able to read here. I'm a beginner, so please bear with me if these questions are fairly basic. The idea is that this repository will be cloned initially, and the developers will be able to use the infrastructure to make their changes to the code before using git aliases to automate some of the more tedious commands and naming schemes we have in place for things like Jenkins.
The issue I seem to be running into when I test with other developers is the constant need to include the custom config file in the path every time the repository is cloned. I understand that this is a requirement for the first time the repository is cloned as you have to set it up somehow, but is there a way to make this a one-time thing? Ideally this sort of configuration would only be used once when we first implement this into the project, and the developers will be able to use the aliases within without any hassle after.
Again, apologies if this is a bit of a redundant question. First time posting and haven't found much insight in the posts from 10+ years ago. Not for lack of trying.
As you stated, yes, Git config is highly local to where it's cloned to; there isn't a good way to have git config propagate from remote repository to the local clone.
If you must, I would just have a shell script and have new developers run it:
#!/bin/bash
if [[ $(git config setup.first) != didit ]]; then
# Set up aliases
git config alias.mycommand '!git something && git something-else'
# Mark this as done so it doesn't run again
# (Also allows devs to remove config if they desire, as long as this is set)
git config setup.first didit
fi
This will modify <git clone dir>/.git/config
adding an alias.
git mycommand
actually executes git-mycommand
There's also a trick with git
subcommands. When you run git foo
, Git looks for a program called git-foo
in the PATH
and executes it. If you affect developer's PATH
variables, you can have Git subcommands execute from an arbitrary directory.
#!/bin/bash
# Saved as /usr/bin/git-mycommand
git something && git something-else
direnv
It might be possible to use direnv or something similar to affect this environment variable and add a directory with git-*
scripts in it to the PATH
.
For example when you have direnv
set up and working on your local machine:
#!/bin/bash
# Saved as /usr/local/custom-git-commands/git-mycommand
git something && git something-else
# Saved as <git clone dir>/.envrc
PATH_add /usr/local/custom-git-commands
Then you can run git mycommand
and it'll pick up /usr/local/custom-git-commands/git-mycommand
and execute it.