azure-devops-dotnet-samples icon indicating copy to clipboard operation
azure-devops-dotnet-samples copied to clipboard

Example for git fork

Open xtreampb opened this issue 7 years ago • 2 comments

Trying to follow the API for forking a repository (first step in a much larger chain). I've realized a fork is just creating a new repository with added source references. Trying to consume this api call: Git Create I'm not sure what to put for the source ref in the URL in addition to what data makes up the body of the request.

I would greatly appriciate an example on how to fork an existing repo from one project to another one, in addition to within the same project.

xtreampb avatar Jun 12 '18 16:06 xtreampb

I am having the same problem. a better example would be appreciated.

petersgiles avatar Feb 26 '20 22:02 petersgiles

Its as simple as this sourceRef=refs/heads/master. This article was useful and would be a good thing to reference in the documentation Git-Internals-Git-References

After a little spelunking I came up with this.

      var stringContent = new StringContent(JsonConvert.SerializeObject(new
            {
                name = $"{name}",
                parentRepository = new
                {
                    id = parentRepositoryGuid,
                    project = new
                    {
                        id = projectGuid
                    }
                },
                project = new
                {
                    id = projectGuid
                }
            }), Encoding.UTF8, "application/json");

            var url = $"{DEVOPSBASEURL}/{projectGuid}/_apis/git/repositories?sourceRef=refs/heads/master&api-version=4.1";

petersgiles avatar Feb 26 '20 23:02 petersgiles