© Vincent Maverick S. Durano 2019
Vincent Maverick S. DuranoUnderstanding Game Application Development https://doi.org/10.1007/978-1-4842-4264-3_7

7. Pushing Your Code to GitHub

Vincent Maverick S. Durano1 
(1)
Minnetonka, MN, USA
 
In software development, securing your code is always a top priority. Unexpected circumstances can occur with your development machine, and of course, you don’t want to lose all the hard work and effort that you put in building the software application. Even if you’re just building a simple prototype and working alone for a project, you never know when more people might be brought onto the project. Typically, when developing an app, here’s a common approach:
  • You’re working with some new code to get it to work

  • You don’t want to break your existing code, so you copy your current code to another folder (Folder A) and continue working in Folder B

  • If you make a mistake, you just delete Folder B and resume with Folder A

This approach is the idea behind version control. Version control is a process that lets you keep checkpoints of your code so that you can refer back to them if needed.

Git is a widely used version control system used to manage code. Code managed with Git is called a Git repository. Also, repos allow you to roll back when you accidentally add something that doesn’t work.

This chapter talks about how to push software source code to GitHub. GitHub is a popular hosting service for source code repositories (Git Repo). Here’s a brief definition of GitHub from the documentation.

GitHub Inc. is a web-based hosting service for version control using Git. It is mostly used for computer code. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.

Microsoft announced that it reached an agreement to acquire GitHub in June 2018 and closed the purchase at the end of the same year.

Using Visual Studio to Push Source Code in GitHub

The first thing you need to be able to push your code in GitHub is a GitHub account. If don’t have one, then you can register here: https://github.com/join?source=header

Download GitHub Extension for Visual Studio

In Visual Studio, select Tools ➤ Extensions and Updates. Click the Online tab in the left pane, and it should present you something like this:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig1_HTML.jpg
Figure 7-1

Adding GitHub extension for Visual Studio

Click Download. You may need to reboot Visual Studio to proceed with the installation of the GitHub extension. After a reboot, you will be prompted with the following screen:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig2_HTML.jpg
Figure 7-2

VSIX Installer license terms agreement

Click Modify. You may also be required to end some processes before starting the modification.

Publishing Your Code

After the installation, navigate to the Team Explorer panel as shown in the following figure:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig3_HTML.jpg
Figure 7-3

Connecting to GitHub

Click Connect, and you should be presented with the GitHub login screen:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig4_HTML.jpg
Figure 7-4

GitHub login screen

Enter your GitHub account credentials to continue.

On the Solution Explorer, right-click the project Solution and select Add Solution to Source Control just like in the following figure:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig5_HTML.jpg
Figure 7-5

Adding solution to source control

This action creates a local git repository with .gitattributes and .gitignore files, as shown in the following figure:

../images/475615_1_En_7_Chapter/475615_1_En_7_Figa_HTML.jpg

.gitignore ignores untracked files—those that haven’t been added with git add; .gitattributes are for tracked files. That is, one file could be processed with .gitattributes and two others could be ignored (just an example).

For more information about customizing how changed files appear on GitHub, see https://help.github.com/articles/customizing-how-changed-files-appear-on-github/

Switch back to the Team Explorer pane, and you will see a local Git Repository added as shown in the following figure:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig6_HTML.jpg
Figure 7-6

Local Git repositories

Double-click the MemoryGame.App repo, and it should present you with the following screen:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig7_HTML.jpg
Figure 7-7

Sync code

Click Sync and it should present you with the following screen:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig8_HTML.jpg
Figure 7-8

Publish to GitHub

Click Publish to GitHub. On the next screen, enter a Name and Description for your repository just like in the following figure:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig9_HTML.jpg
Figure 7-9

Commit publish

Click Publish.

When successful, it should create an empty GitHub repo to your GitHub account portal as shown in the following figure:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig10_HTML.jpg
Figure 7-10

Repository created successfully

Click the Changes item and you should be presented with this:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig11_HTML.jpg
Figure 7-11

Enter a commit message

Enter a message for your first commit and then select Commit All and Push as shown in the following figure.
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig12_HTML.jpg
Figure 7-12

Commit all and push command

This command stores all your changes locally and pushes them to your GitHub remote repository URL. The following figure shows when a successful commit and push is done.
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig13_HTML.jpg
Figure 7-13

Source code successful pushed to GitHub

To verify that your changes were really pushed to your GitHub repository account, you can navigate to the GitHub repository URL generated from the previous step. For this example, it generates this remote URL:
  • https://github.com/proudmonkey/Apress-Game-Development-Xamarin.Forms-ASPNET
Here’s a screenshot of the source code repository published on GitHub:
../images/475615_1_En_7_Chapter/475615_1_En_7_Fig14_HTML.jpg
Figure 7-14

GitHub public source code repository

For more information about using GitHub, see https://guides.github.com/activities/hello-world/

GitHub Repository and Source Code

You can view and fork the source code here: https://github.com/proudmonkey/Apress-Game-Development-Xamarin.Forms-ASPNET

References

Feel free to read more about the topics covered in this book by going through the following references: