Automatic project structure/git creation in Windows

automatic project creator

While working in projects on a daily basis, as I do for YouTube videos, we tend to create the same folder structure and related repositories every time, as we move to the next project.  For me, it is like creating folders for video, code, uploaded video, schematics and so on and in my most of the video for YouTube, I always create almost same folders. Along with that, I create GitHub repository to host the codes that I use in the project or tutorial to distribute. And I hate doing the same thing over and over, so I thought of making it automatic somehow, starting from folder creation to the remote git repo. As my primary machine is a Windows 10 one, I went with bash scripting. You can do that with any programming language like C++ or Java, but I wanted a simple one with not much development time. So this post is all about that.

First of all creating folders and navigating is pretty easy. It involves commands like mkdir and cd only. The script when run asks for the name of the project, and it takes that as the primary folder name, and after that, it creates subfolders under it.

@echo off
set /p project="Enter ID: "
echo Project name is %project%

cd C://Workspace
mkdir "%project%"
cd "%project%"
mkdir Blog Code Edits Raw Thumbnails Upload
mkdir Code\Lib Code\Circuit Code\Docs Raw\Images Raw\Videos Raw\Unused Raw\B_Rolls Raw\Screen_Capture
cd Code

I just want to add code folder to my git repository, not all the folders. So inside the code folder a README.md file is first created with a line of text with the name of the project and start date. After that, it initializes an empty git repository and does a commit with the README file added.

echo Started working on project on %DATE:~10,4%%DATE:~4,2%%DATE:~7,2% %project% > README.md
git init
git add .
git commit -m "Starting the project on %DATE:~10,4%%DATE:~4,2%%DATE:~7,2%"

** For above script to execute I assume you have git installed in your system. If not you can download from here.

After that, it justs a matter of grating a remote repository in any of the cloud git services that you are using. I am using GitHub, and that’s pretty easy with the provided API by Github. If you are using any other service like BitBucket or Gitlab, you can explore their APIs. In windows to call API from the bash script, we need to install curl, as it does not as default like in Linux. To install curl support download from here and just install it.

After curl is installed, we need to get an access token from here. To obtain the token, you needed to be logged in and joined the developer program. To do so click on the Generate new token button as shown in the screenshot.

Github token screenshot

In the next screen put a description and check the required scopes that you want to use it for. For this project check the repo tick and leave others. If you’re going to explore other scopes, you can certainly do so. Click on the Generate button and copy the token in the next screen.

access tokens

***Please don’t try to use the above-shown token; I have already removed it.

Now after getting the token, we can invoke the GitHub API. And the endpoint is https://api.github.com/user/repos. With curl, it looks like,

curl.exe -i -H "Authorization: token _Your_Token_" -d "{\"name\": \"%project%\", \"private\": true }" https://api.github.com/user/repos

Just don’t forget to replace with_Your_Token_ your token just obtained. After the token, the script creates a remote repo and add that to the local repo and push the initial commit.
C:\Program^ Files\Portable^ Installations\curl\bin\curl.exe  -i -H "Authorization: token _Your_Token_" -d "{\"name\": \"%project%\", \"private\": true }" https://api.github.com/user/repos
set url_gh=%project: =-%
git remote add origin https://github.com/oksbwn/%url_gh%
git push -u origin master
Demo Video
I hope it will help in some way. Cheers !!!!!!
Complete Code
@echo off
set /p project="Enter ID: "
echo Project name is %project%

cd C://Workspace
mkdir "%project%"
cd "%project%"
mkdir Blog Circuit Code Edits Raw Thumbnails Upload
mkdir Code\Lib Raw\Images Raw\Videos Raw\Unused Raw\B_Rolls Raw\Screen_Capture
cd Code
echo Started working on project on %DATE:~10,4%%DATE:~4,2%%DATE:~7,2% %project% > README.md
git init
git add .
git commit -m "Starting the project on %DATE:~10,4%%DATE:~4,2%%DATE:~7,2%"
C:\Program^ Files\Portable^ Installations\curl\bin\curl.exe  -i -H "Authorization: token ____Replace_eith_your_github_token___" -d "{\"name\": \"%project%\", \"private\": true }" https://api.github.com/user/repos
set url_gh=%project: =-%
git remote add origin https://github.com/oksbwn/%url_gh%
git push -u origin master
Repository

oksbwn/Automatic-project-script

A easy to you windows script to create project folder structure and initialize remote github repository based on project name with just a click.

0 forks. 0 stars. 0 open issues.

Last commit by

 

Bikash Panda
Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts