Create template git-repo in in azure devops
Asked Answered
T

3

9

I have a git-repo in Azure DevOps that I want to use as a template for starting new repos, but without the commit history of the original. GitHub has this nice feature, however I can't find a good approach in DevOps. Is the only way to clone it, remove .git and bind it to a new empty repo?

Tolliver answered 27/4, 2020 at 6:26 Comment(2)
There's an outstanding feature request for this: developercommunity.visualstudio.com/idea/1135723/…Herta
I too waiting for this requirement to have OOTB in Azure DevOps. In the meantime, I found Stephen Allwright's useful blog article to do it more cleaner. Read more stephenallwright.com/project-template-repository-azure-devopsShutin
B
4

There is no out of the box solution on Azure Repos but you can use this workaround (Using a git repository as the base of a new project):

Instead of doing a full clone only to delete the .git directory again, you can only retrieve the archive of the repository you want to start from.

$ mkdir new-project/
$ cd new-project/
$ git archive --remote="${giturl}" HEAD | tar -x
$ git init
$ git add -A
$ git commit -m "Staring off with revision ${rev} of repository ${repo}."
Bankhead answered 27/4, 2020 at 8:50 Comment(1)
thanks, this works but its prone to errors. Our solution was to clone the "template" repo, then create a new repo, clone it and manually copy the needed stuff from the template to the new. I feel like a cavemanTolliver
V
0

I am afraid there is currently no such feature as Creating a template repository in Azure devops.

As a workaround, because there is a feature to create a template repository in github, so we can first import the repo from azure devops to github.

enter image description here

Then create a template repo in github, and finally import the created template repo into azure devops.

In addition , I think what you want is a good idea! You can post this feature request on our UserVoice site , which is our main forum for product suggestions. The product team would provide the updates if they view it. Thank you for helping us build a better Azure DevOps.

Vodka answered 28/4, 2020 at 5:50 Comment(1)
It is not a really a viable solution to put our company stuff on github and import to devops. There is templates for all other features in DevOps but not this.Tolliver
P
0

I recommend using Forks.

enter image description here

  1. Create your template repository.
  2. Choose to fork this to a project repository - to be based on the fork.
  3. Later on, any updates to the template repository are easily sent to projects using the template with pull requests (PRs).
  4. The only danger is accidentally pushing project changes up to the template repository as Azure DevOps designers seem to not have considered this and for every PR in a project, the 'default' branch is the upstream (template) repository and the default cannot be changed to the project repository.
  5. I have reported this design flaw to Azure DevOps, and pushed really hard to have it fixed and I was told it is in the backlog, but there is no visibility on that so who knows what will happen with it. Below is one ticket I raised, and another was with my companies license support.

https://developercommunity.visualstudio.com/t/For-New-PRs-From-a-Forked-Repository-Do/10402825

Peat answered 16/10, 2023 at 12:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.