Can you ignore files/folders when making a Repo from a template? #22183
-
I set up a GitHub Repository as a template so that other people can use it to create documentation or similar. That said would I like to make it, so that when people click the “Use this template” button, that the copied Repo won’t contain certain files or folders like the README.md. Is there a way to set a file or similar to define files/folders that should not be copied from the template repository? (If not, then I hope it could be considered as a feature in the future.) |
Beta Was this translation helpful? Give feedback.
Replies: 21 comments 30 replies
-
Hi @andre601, Thank you for being here. At the moment there isn’t a way to ignore files when creating from repository templates. Ideally there will be an implemented |
Beta Was this translation helpful? Give feedback.
-
So excluding files or folder being added to the zip also isn’t possible then? I got this repo which has template files, these are added in the zip when the repo is downloaded. I would like to exclude those. |
Beta Was this translation helpful? Give feedback.
-
I hope this feature will be included soon… |
Beta Was this translation helpful? Give feedback.
-
+1 for this! Specifically, when making a repository from a template, I don’t want to include package manager lockfiles. |
Beta Was this translation helpful? Give feedback.
-
It’d probably make sense to put it in Just to add to how useful this would be… I’m making a website template, and it’d be great to only give users the files they really need. There’s a test bed page for my own development purposes that they don’t need. And there’s a bunch of documentation that should stay in the same repo (because it’s for the template), but doesn’t need to be duplicated to every clone of the template. |
Beta Was this translation helpful? Give feedback.
-
I think having it as a dot-file in the root, similar to .gitignore would make a bit more sense, in case that any other git repo-site (bitbucket, gitlab, gittea, etc) would want to adobt this idea in the future. I for myself see a new potential feature alongside the .gitignore file that could help improve any future git repositories… But that’s just my thinking. |
Beta Was this translation helpful? Give feedback.
-
There is a way of solving this (somewhat manually) by using workflows that trigger This approach is pretty nice, but has 2 major cons:
@AndreaGriffiths11 I’m a bit late here but if there is some internal ticket on this feature, it would be wonderful if it went beyond a mere “ignore” file and instead had some interactivity and integration with Github Actions and workflows. |
Beta Was this translation helpful? Give feedback.
-
Any updates? We'd love to have this feature. |
Beta Was this translation helpful? Give feedback.
-
I'd also be very interested in this feature. I'd like to have workflow in the template repository that can automatically keep it up-to-date with submodules, but I don't want the generated repositories to include the workflow. |
Beta Was this translation helpful? Give feedback.
-
+1, ignoring files such as how to use the template is reasonable. Something like |
Beta Was this translation helpful? Give feedback.
-
As a solution for now, I'm using GitHub Actions to "clean" the repo for the user when they generate it: name: first-time-setup
run-name: first time setup of repo
on:
# run when branch created (repo generated from template)
create:
# only keep latest run of this workflow
concurrency:
group: first-time-setup
cancel-in-progress: true
jobs:
first-time-setup:
# ensure run only once, when repo generated
if: github.run_number == 1
runs-on: ubuntu-latest
steps:
# get main branch repo contents
- name: Checkout code
uses: actions/checkout@v3
# remove files not needed for user instance of template
- name: Remove unneeded files
run: rm -f README.md demo.md testbed.md
# personalize readme for user
- name: Init readme
run: |
echo "
Personalized readme text. Hello ${{ github.repository_owner }}!
" > README.md
# save changed files
- name: Commit changed files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Setup repo" This actually turns out to be a nicer solution because I can do more than just exclude certain files. I can customize files however I want based on user info like user/org name, repo name, etc. with the However, this only works when "generating" (i.e. "Use this template"), and not when forking, because when you fork, GitHub Actions is not enabled yet, and there is no workflow trigger for when Actions is first enabled. You could perhaps call the above workflow from some other workflow that you know will run at some point, like a "build live site" workflow. |
Beta Was this translation helpful? Give feedback.
-
My use case is that I have a CODEOWNERS file that protects the template, but I don't want the same CODEOWNERS present in the derived repo (because it doesn't make any sense to have it there). The script solution here doesn't work for me because it runs after the derived repo is created, which means the first change in the new repo is subject to CODEOWNERS. |
Beta Was this translation helpful? Give feedback.
-
+1 Any updates on this would be appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
-
+1 for this feature |
Beta Was this translation helpful? Give feedback.
-
+1 please do this |
Beta Was this translation helpful? Give feedback.
-
+1 would be nice to have |
Beta Was this translation helpful? Give feedback.
-
Chiming in to say that this is really needed. I have a template to run tests on the project, but it shouldn't be present in the release when users create a repo based on the template. I don't want to use up their action minutes for something that they don't need. Considering forks don't even run workflows by default, why would repo templates be different? |
Beta Was this translation helpful? Give feedback.
-
I think Github needs to add official support for this with a
|
Beta Was this translation helpful? Give feedback.
-
Is there any updated on this ? @AndreaGriffiths11 , when can we expect this feature ? |
Beta Was this translation helpful? Give feedback.
-
In the meantime, the best way we managed to workaround this for HydePHP was by adding a workflow that runs on the # Read the .gitattributes file line by line
while IFS= read -r line; do
# Check if the line contains 'export-ignore'
if [[ $line == *"export-ignore"* ]]; then
# Extract the path from the line
path=$(echo "$line" | awk '{print $1}')
rm -rf "$path"
fi
done < ".gitattributes" See hydephp/hyde#257 and this Gist https://gist.github.com/caendesilva/a7aa411b218d0fc5b5e4f5e884bc2350 |
Beta Was this translation helpful? Give feedback.
Hi @andre601,
Thank you for being here. At the moment there isn’t a way to ignore files when creating from repository templates. Ideally there will be an implemented
dot ignore
file for repository templates, and I’ve passed that suggestion to the team for consideration. Although I can’t guarantee when or if this feature would be implemented please know your feedback is in the right hands.