Is there a way to clone all the master
branches from all the projects uploaded under 1 account.
I have a requirement to backup all the code in master
branch every week.
Is there a way to accomplish this using git, Powershell or any other way?
Note that I required to do this task in a Windows environment.
(1) Right click inside the folder you want all of the repos to clone to (2) select "Git Bash Here" - Bash window will open (3) Edit the script with your org name, then copy and paste it into the bash window (maybe make sure line endings are unix based, not sure, I did just to be safe). (4) it should start running.
In Team Explorer, select Connect to open the Connect page, and then choose Clone under Local Git Repositories. Enter the clone URL of the remote Git repo that you want to clone, verify the local folder path where you want to create the local clone, and then choose Clone.
Cloning the whole TFS Project CollectionYou can clone all projects by specifying $/ as the tfs-repository path. If you do not specify a git repository name, it will clone into tfs-collection .
To clone a Git repository, you will first copy the remote URL from your repository hosting service—in this case GitHub. You will then use the Git clone command followed by the remote repo's URL. If you are working with a private repository, you will be prompted for your remote hosting service credentials.
You can do it with PowerShell and TFS Rest API.
First of all, get the projects with Projects - List API, then get to each project the repositories with Repositories - List API and clone only the master.
For example, a simple PowerShell script that do it:
$collection = "http://tfs-server:8080/tfs/collection-name"
$projectsUrl = "$collection/_apis/projects?api-version=4.0"
$projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -UseDefaultCredentials -ContentType application/json
$projects.value.ForEach({
$reposUrl = "$collectionurl/$($_.name)/_apis/git/repositories?api-version=4.0"
$repos = Invoke-RestMethod -Uri $reposUrl -Method Get -UseDefaultCredentials -ContentType application/json
$repos.value.ForEach({
git clone $_.remoteUrl --branch master --single-branch
})
})
I did not see that feature directly in TFS, but if the VSTS API is also available for your on-premise TFS instance, you can:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With