GitStub - a GitHub-first development boostrapper for dotnet core
Tags: dotnet, globaltool, github, opensource
Published: 2019-04-15 16:50:09


---
title: GitStub - a GitHub-first development boostrapper for dotnet core
published: true
description: GitStub is an open source dotnet core global tool for rapidly creating a GitHub repository and connecting your code, be it a new or existing project, from the command line.
tags: #dotnet #globaltool #github #opensource
cover_image: https://i1.pickpik.com/photos/956/664/989/cup-plant-seedling-planting-preview.jpg
---


###tl;dr

My first foray into my own open source project is a tool to lower the barrier to getting code up onto GitHub.  I created it because I wanted to start a different open source project and in the process of learning what to do, realized that there are a number of repetitive steps.  At first, I sought to create myself a set of scripts that would ease the process by interacting with the GitHub rest api and the dotnet core cli.  Soon, I realized that taking these steps and creating a cross platform dotnet core global tool would both be better in terms of ease of use and also allow me to share this with the widest audience - hopefully saving someone else some time and tedium.

You can install it and try it yourself with
`dotnet tool install --global gitstub`

For issues, requests and ideas to make it better
[GitStub on GitHub](https://github.com/erikest/gitstub)

##Problem

You want to create a new dotnet core project so you

```shell
mkdir  MyKillerWebApp
cd MyKillerWebApp
dotnet new webapp
```

Actually, it needs a solution and a little rearranging you decide

```
mkdir -p src/MyKillerWebApp
mv * src/MyKillerWebApp
dotnet sln -n MyKillerWebApp

```

Then you want to put it into a git repository, but first you need to find a `.gitignore` to add - maybe you have one you used before in another project
```shell
cp /users/myuser/repos/someotherdotnetproject/.gitignore ./
```
Now you can set up your first commit
```shell
git init
git add -A
git commit -m "First Commit! The only way is up from here!"
```

At some point you realize, it should actually be a GitHub project, because you want to share this killer webapp with the world.  From here, you go to your browser and GitHub.com, you log in, create a new project, filling out the details.

A few minutes later, the GitHub project is there, but it and your local git are not connected so you still have to
```shell
git remote add origin https://user:pass@github.com/user/projectName.git
git push --set-upstream origin master
```

Finally, you've got everything on GitHub and you can iterate from there.


Or maybe you stop somewhere before that, before even creating the local git repo.  You tell yourself, "once it is 'worth it'" you'll take those steps and make a GitHub project.  Then maybe you do, maybe you don't.  Perhaps you get second thoughts - what if my code isn't 'good enough' yet.  Sometimes though, code that is good enough or would be good enough just stays on your laptop, where it dies.  Or another time, away from your machine, you are with another dev and you think - "Oh! I started working on something like this - but, ack, it's on *my* machine, so I'll have to go create a GitHub project and push it up for *you* to see it... maybe when I get back to my computer."  Or maybe it's not that big of a barrier and you do go through those steps every time - but wouldn't it be nice if it was just a little faster, a little easier?

##Solution - GitHub-first development with GitStub

The **goals** of this project are two fold.  

1. **Save time** - simply put, these are repetitive tasks, they are begging for automation.
2. Promote a development paradigm where you start projects, public or private, on GitHub and commit right away - **GitHub-first**.  
    * This not only makes the code immediately available everywhere, it also facilitates your progress in open source by having the initiation of the project start the cycle of contributions.  You get to overcome your fear and perfectionism and replace it with continual public improvement as a feature of your dev life.  
    * By combining that with dotnet new project templates, you get a bootstrapped, scaffolded project up and ready to be iterated.  The first commit is the template, outta the box.  Your second commit will contain all the deltas between the base template and what value you've added thus far - and away ye go!
    * Hopefully, it takes one small barrier out of the way that might stop you, on the margin, from trying something and putting it on GitHub because you "can't be bothered" to set up the project and connect everything.

##How To Use

First, install the tool using

`dotnet tool install --global gitstub`

Now, suppose I want to start a new console application in a folder called `MyKillerApp`.
From the command line in the that folder, I can

```shell
gitstub console -gsu myusername -gsp mypassword
```

By default, `gitstub` will use the current folder as the name for a public project on GitHub.  The two parameters after `console` are my GitHub username (`-gsu`) and GitHub password (`-gsp`).  This will do the stuff, including adding a .gitignore file that ignores most of the common things for dotnet projects.  A few moments later, voila, I can now go to https://github.com/myusername/MyKillerApp and see everything there.  If I open up the project in Visual Studio, I can proceed to use the Team Explorer window to process further commits.  

Perhaps I want a little more structure with a solution/project laid out like
* /
    * MyKillerApp.sln
    * src/
        * MyKillerApp/
            * MyKillerApp.csproj
            * \<other files\>

Then I can say
```shell
gitstub console --sln -gsu myusername -gsp mypassword
```

And `gitstub` will create a solution and a project and arrange them thus.

If I had a different name I wanted to use for the project and solution, I can specify that as well

```shell
gitstub console -gsr "FirstKillerApp" -gss "KillerApps" -gsu myusername -gsp mypassword
```
If it needs to be a private repository, then I can add `--private`.
```shell
gitstub console -gsr "FirstKillerApp" -gss "KillerApps" -gsu myusername -gsp mypassword --private
```
I can give the GitHub project a description and I can change the first commit message as well

```shell
gitstub console --sln -gsu myusername -gsp mypassword -gsd "The best app yet" -gsc "Initialized with the console template"
```

If my template has additional parameters, I can pass those along - any parameter not reserved for `gitstub` will be passed to the `dotnet new` command in original order, so

```shell
gitstub webapp -au Individual --sln -gsu myusername -gsp mypassword -gsd "Authed web app example" -gsc "Initialized with webapp and individual authentication"
```

will run `dotnet new webapp -au Individual` at the project creation step.

If I have an existing project, I can still use `gitstub` to get things moving by including the `--existing` switch.  With this, `gitstub` will skip the project/solution creation step and just commit what's already in the folder.  It still adds the `.gitignore`, so it won't pick up obj/bin/.vs and other stuff.

```shell
gitstub -gsu myusername -gsp mypassword --existing
```

##What's Next

You can follow along, post issues, feature requests, tell me how to be better at this open source thing, etc. at the [GitHub repo](https://github.com/erikest/gitstub).

In my sights for future features are
* getting rid of having to pass username and password each time by implementing GitHub OAuth and caching a token for the session.
* a `devops` switch that would create an Azure Devops project and connect it to the GitHub project
* a `nuget` switch that would search the template output for a .nuspec file and modify it with the appropriate project repository and project name

I'm very open to feedback and suggestions, so let me know what you think!