How to Share Code
11 Jun 2017
Sharing Your Code
Like many open source projects and communities, we use “GitHub” to store, version and share our source code. At the end of each code dojo session we would like you to add your code to our repository so that others can learn by viewing all the various solutions. As using GitHub for the first time can be quite daunting I’ve put this step by step guide to get you started.
In your browser go to https://github.com/ and complete the form allowing you to sign up.
Note: The username will be used to form part of the URL to your source code. For example, one of my repositories has the URL https://github.com/davidBetteridge/TaskVisualiser as my username is davidbetteridge.
After your username, has been accepted you will be asked what type of plan you wish to use. For now, pick the Unlimited public repositories for free option.
Warning: Picking the free plan only allows you to create public repositories. This means that any source code you store in github will be visible to the entire world. This includes any files you check in with passwords in!
The next task is to install some software on your development machine. Although graphical tools do exist, most developers use the command line interface.
First make sure that git isn’t already installed by opening a command prompt and typing “git”. If it’s already installed, then you can skip the rest of this section.
In your browser visit https://git-scm.com/downloads and click the icon for your operating system.
Download and install the version for your operating system. (For windows this is just a case of following the wizard, I haven’t tried it on Linux or Macs.)
Now we are ready to start adding some source code. There are a few steps to carry out so it seems quite complicated at first but you will soon get used to it.
When you “Fork” the source code it means that you are taking you own copy so that you can work in complete isolation to the original code.
In your browser visit the URL https://github.com/yorkCodeDojo and find the repository for the code you were working on during the code dojo.
Once you are viewing the repository, click the “Fork” button
This should create a copy of the repository, but within your own account.
Next is to clone the code from your GitHub account onto your development machine.
Click the Clone or Download option and then copy the URL onto your clipboard
Open a command prompt on your development machine, ensure you are in the folder in which you wish to create the code and type git clone followed by the url
If it all goes to plan, then it should download all the current code in the repository onto your machine
Now you can add your pair’s source code to your local copy. Begin by making a folder based on your first names and language used. For example, david_daniel_fsharp. Try to avoid non-standard characters such a # sign.
Once you have added your source code to the folder use the git add command. You can either use git add . to add all files, or git add filename to add individual files
Type git status to view the files you have just added. If you have added files by accident, then use the git reset command.
The next step is to confirm your changes within the source control system on your development machine.
For this type git commit -m “Message” where message is a comment you wish to store against the check in.
Currently your source code is only on your local machine. You need to also push it up to your account on GitHub. For this we use the git push command.
If you now look at your account on git hub you should see the code, you have just added.
Finally, you need to request that your changes are pulled into the original repository on the York code dojo account
Click the New pull request button
And then Create pull request
Add a comment and then click Create Pull request (again!)
I should now get an email telling me there is a new pull request. Once I’ve reviewed it I’ll click Merge and your source code will be included.
David Betteridge is a Co-Founder of YorkDevelopers.org, a dedicated group of software engineers in York providing meetups for technology professionals in York. David is an accomplished Software Architect with a proven track record of designing scalable solutions.