More PowerShell Function Hacks



Following up on my last post (PowerShell Profile Shortcuts), I have another really cool hack if you, like me, are creating many github repositories for hackathons or demos.


Wouldn’t it be cool if you could use the following from the command line

createrepo mynewrepo

And it would

  1. Create a repo on git hub
  2. Clone it locally
  3. CD into that directory
  4. Create a file
  5. Create a package.json
  6. Create a basic gitignore file
  7. Add all files using git add .
  8. Create a commit
  9. Push back up to your repo

Well you can, just create a function in my powershell profile to do all of this. (See below)

There are three prerequisites:

  1. Install gh —   (npm install -g gh)
  2. Install gig       (npm install -g gig)
  3. Set up npm init defaults (
  4. change references to your own github account (says YourGitHubAccount in code now)

To modify your powershell profile

If using VS Code  just type code $profile from your powerhell command line. Otherwise, there are plenty of tutorials on how to modify your profile like this one (

Either way, once you get it open, just paste this in (after prerequisites above) and change the github account to yours.

Function createrepo($reponame){
  #need to install gh --- npm install -g gh
  gh re --new $reponame -B false
  git clone$reponame.git
  cd $reponame
  #need to install gig npm install -g gig
  gig gen node
  #need to have defaults set up for this (
  npm init -y
  #now add a readme file
  echo "# $reponame" >>
  echo "## Synopsis" >>

  echo "At the top of the file there should be a short introduction and/ or overview that explains **what** the project is. This description should match descriptions added for package managers (Gemspec, package.json, etc.)" >>

  echo "## Code Example" >>

  echo "Show what the library does as concisely as possible, developers should be able to figure out **how** your project solves their problem by looking at the code example. Make sure the API you are showing off is obvious, and that your code is short and concise." >>

  echo "## Motivation" >>

  echo "A short description of the motivation behind the creation and maintenance of the project. This should explain **why** the project exists." >>

  echo "## Installation" >>

  echo "Provide code examples and explanations of how to get the project." >>

  echo "## API Reference" >>

  echo "Depending on the size of the project, if it is small and simple enough the reference docs can be added to the README. For medium size to larger projects it is important to at least provide a link to where the API reference docs live." >>

  echo "## Tests" >>

  echo "Describe and show how to run the tests with code examples." >>

  echo "## Contributors" >>

  echo "Let people know how they can dive into the project, include important links to things like issue trackers, irc, twitter accounts if applicable." >>

  echo "## License" >>

  echo "A short snippet describing the license (MIT, Apache, etc.)" >>
  git add .
  git commit -m "first commit"
  #if you dont want it to prompt you for credentials every time run this : git config --global credential.helper wincred 
  git push -u origin master