The best VPN 2024

The Best VPS 2024

The Best C# Book

How to use bat file clone projects in batch?

Spread the love

How to use bat file clone projects in batch? Team development uses Team Foundation for source code management. Usually, for large projects, writing a BAT batch clone project is very convenient for pulling the project for the first time. You don’t need to execute boring git clone commands one at a time, for thousands of projects. , This has to be taken until when, so lazy people have to think of something lazy, using batch commands can easily get it.

Remember that when using the universe’s first development tool VS earlier, the team source code management choice TFS is the choice of many small partners. When git comes out, Microsoft will also support the use of git management source code in Team Foundation in a timely manner, and you will be very happy. Use git to clone the repository, but for large projects, it is very tiring to clone thousands of projects at once by hand.

Team development uses Team Foundation for source code management. Usually for large projects, writing a BAT file batch clone project is very convenient for pulling the project for the first time. You don’t need to execute boring git clone commands one at a time, for thousands of projects. Project, this has to be closed until when, so lazy people have to think of a lazy way, using batch commands can easily handle it.

How to use bat file clone projects in batch
How to use bat file clone projects in batch

BAT file clone projects

If you want to clone 1000 projects in batches at once, score a few steps to achieve:

  • Step 1: Get the clone address of each project first
  • Step 2: Save the result to a notepad file (note that the encoding is ANSI)
  • The third step: compile the bat file
  • Step 4: Execute the bat file
  • Step 5: Drink tea and come back

Script to get the project clone address

If you want to clone 1000 projects in batch in Team Foundation , you must first find a way to get the address of each project, you can directly enter the project version control interface, it is best to use browsers such as chrome, edge, firefox, because you need to use it Developer tools, write a script in the console, as shown in the following figure:

How to use bat file clone projects in batch
How to use bat file clone projects in batch

On the left is the list of projects in the repository. The clone address of each project can be obtained by writing a js script. The code is as follows:

var arrary= document.querySelector(“#tfs_tnul1”).querySelectorAll(“li”); var url=””; for(var i = 0; i< arrary.length; i++){ url+=”http://jhrs.com/tfs/UniversityProjects/jhrswpf/_git/”+ encodeURIComponent(arrary[i].title)+” “+arrary[i].title+”\r\n”; } console.log(url);

Then it looks like this in the console. Note that the above code is on one line, do not wrap.

Console-Script
How to use bat file clone projects in batch

After the code is written, press Enter to execute it, and the result is as follows:

console-result
How to use bat file clone projects in batch

Well, after execution, we got the clone addresses of all projects.

Save results to notepad

Why save the results to Notepad? It is because we will read the clone address in the file in the next bat file. Some friends will ask, why not put the address directly in the bat batch file? The answer is because the cloned address exists in Chinese, and the URL address is encoded, and an error will be reported when it is directly put into the batch file for execution. If you don’t believe it, you can try it yourself.

Create a list.txt file with Notepad and use ANSI encoding.

clone-address-list
save-location
How to use bat file clone projects in batch

The above picture is the list.txt file, the file must be saved with ANSI encoding, otherwise there will be an error, because the batch processing Chinese garbled.

Write a bat file

The content of the bat file is as follows.

@echo off
echo Press any key to start batch cloning
pause
for /f "delims= tokens=1,2" %%i in (list.txt) do ( 
        echo %%i %%j
        git clone %%i %%j
)
echo 'git clone finish!'
pause

vHow to use bat file clone projects in batch

The above code is the key to batch clone projects by reading the list.txt file through bat. Create a new notepad document, copy the above content, and save it. The file encoding is selected as ANSI encoding, the default is UTF8, and the encoding can be changed by saving as.

Execute bat file

After the bat file is written, execute it, and the batch cloning effect is as follows:

batch-clone
How to use bat file clone projects in batch

Because there are many projects, it takes a long time to wait. It’s best to have a cup of tea and come back and see.

Conclusion

I found that the team members cloned projects one by one, which was really troublesome, so I spent some time researching it and used these lazy methods to realize batch cloning projects. Finally, I don’t need to type the git clone command one by one, then connect Then copy the clone address of the next project, and then git clone.

I am an IT rookie , do you like this article? If you like, use the rewards below to support me and give me the motivation to write.

Leave a Comment