Monday, September 6, 2021

how to add a list of empty folders to github in windows environment?

When we setup the project structure in the development. the Github have prevent us to push all empty folder to the GitHub Repository in remote server. we can use gitkeep utility in the Macs and Linux environmen to create gitkeep for those blank folder. we cannot gitkeep in the Windows environment. but there is a work around. we can use the powershell scripts to loop through all subfolders under the current project folder and add .gitkeep file in each empty folder. then we can upload those folders to the server.

here is the code to be execute in the windows PowerShell ISE, you should copy it to your windows PowerSehll ISE and replace {Your Current Project Folder path} with your own folder path

Get-ChildItem '{Your Current Project Folder path}' -Recurse -Directory | 

Where-Object {[System.IO.Directory]::GetFileSystemEntries($_.FullName).Count -eq 0} | 

ForEach-Object { New-Item ($_.FullName + "\.gitkeep") -ItemType file}




No comments:

Post a Comment