I usually end up looking for these steps every time I write a blog post with a code sample that I in the end push up to GitHub. So the steps I do are:
- Creating and committing to a local git repository
- Create a GitHub repository with License (and readme)
- Configure the local repository to push it to GitHub
Step one is usually done by creating a new Solution in Visual Studio which automatically adds the gitignore file according to my C# project which is very helpful to not ending up committing the bin folder and the NuGet package binaries.
After finishing my solution I go to GitHub and create a new repository, in the setup process you can add a License file and a blank readme. You could also add the gitignore at this step but as some of my code gets thrown away as it is of no use I tend to first start locally and then push the solution once I feel it has some value to add.
Now once all is setup on GitHub I use the Git Shell which you get after installing GitHub for Windows . There navigate to the root of your project and add the repository (you find the uri after creating the repo) with the following line:
git remote add origin https://github.com/your-account/the-repository-name
Next verify that your branch has been successfully added as a remote branch:
git remote -v
First we have to get the remote branch to our local repository:
Then set the upstream branch:
git branch --set-upstream-to=origin/master master
Pull the license and possible readme (et al):
Now you can simply push your main branch to GitHub:
And all is good :-)