Automation Script for Git Flow on PowerShell

Jin Kim
4 min readOct 18, 2020

--

Written by Jin Kim

Hi! My name is Jin Kim and I am a software developer hoping to help you save time with your code by providing you short-cuts for git commands. In this specific blog, I will be providing you tips to create your “ACPing” a faster experience. Thank you for your time in reading this blog, I am very excited about this!

Github has been the grand central station for developers. As I started pushing up code, I noticed the redundancy of git add. git commit …. This is great and all but learning about automation using the PowerShell, really got me thinking about efficiency here. The following script is something I quickly put together in hopes to push your current code from any stage of development with one command. I hope you will find this script helpful.

At the end of this demo you will be able to push to the Github, using gitpush or commit depending on what operation you want to perform.

Automation for the WIN! (Source: Getting Ready GIF By MANGOTEETH)

Pre-requirements:

  • Code Editor
  • PowerShell
  • git
  • And awesome you!

For this demo I used my bread and butter, VS Code, but any editor should be sufficient.

Step 1. Type code $PROFILE in your terminal.

Step 2. This will show the environment profile script of PowerShell.

Step 3. Type in this code to the code editor:

You will notice in-line comments describing what this function does further in depth.

# This is the function to push the current change into the branchfunction gitpush {param([Parameter(ValueFromRemainingArguments = $true)][String[]] $message)# Simple git add command to stage the filesgit add .## if the first parameter wasn't passed inn it will place current date as a commit messageif ($null -eq $message){$DATE=Get-Dategit commit -m "$DATE";}## if the parameter was passed in it will be a messageelse{git commit -a -m "$message";}## prompting the current user what branch do you want to push it up.Read-Host "what branch?" $branch## if the branch wasn't specify it will be pushed to the masterif($null -eq $branch){git pushWrite-Host "It's been pushed";}## if the branch is specify it will be pushed to that specific branchelse{git push origin $branchWrite-Host "It's been pushed";}}

Step 4. Save this script and restart your PowerShell by turning it off.

Step 5. Using gitpush <commit message> , it will prompt you for which branch you would like the push to, your default will be master, then it will be pushed.

  • As a side note, I found that you would need to authenticate your Github account. After that, it will not ask for authentication anymore.
This will be screen you will get at first.
For the first time user, you will be asked with this authentication.
After everything is pushed it will be giving successful message.

This has been some PowerShell scripts that I am hoping to help some folks who want to get their code up right away!

BONUS!! If you wish to commit, not to push the whole code yet, try this block of code.

## Commit function that will be used to commit codes not PUSHfunction commit {param([Parameter(ValueFromRemainingArguments = $true)][String[]] $message)# Same ol git add commandgit add .## If the message wasn't passed with function call it will be date that will be committed as a messageif ($null -eq $message){$DATE=Get-Dategit commit -m "$DATE";Write-Host " It's been committed";}## If the message was passed it will be committed with given messageelse{git commit -a -m "$message";Write-Host " It's been committed";}}
Example of committing for awesome code.

THANK YOU! :)

- Jin

--

--

Jin Kim
Jin Kim

No responses yet