Setting up your GitHub repository – An Introduction to IoT Architecture, Hardware, and Real-Life Applications

GitHub is a code repository platform that is used for version control and collaboration on your code. With it, developers can track changes to code and collaborate on a project, while also setting extra restrictions for changes as part of best practices such as letting developers review each other’s code and merge changes from anywhere. We will be using GitHub throughout this book for you to both use the platform to pull the code that we use throughout our chapters and put in your code.

Setting up your GitHub account

To start, we will create our GitHub account to use to set up our repository:

Navigate to https://github.com/ and click on the Sign Up button in the top right.

Enter your email, password, and username as prompted. Check your email for verification and log in to GitHub.

You now have a GitHub account, which is the first step for setting up our version control environment and for making optimum use of the resources of this book that are ready for you to pull onto your local environment.

Setting up your GitHub CLI

When you pull code or create local repositories to push up to GitHub, it is much easier if you use the command-line interface (CLI). The following are the steps that you need to take to install the CLI on your laptop:

Assuming you are on Windows, you will need to go to https://github.com/cli/cli/releases. Navigate to the latest release (at the time of the writing of the book, it is 2.21.1, but this may change, so navigate accordingly) and download the file that ends with windows_amd64.msi.

Follow through with the default installation prompt and install the CLI in a location of your choice.

In the case that it is not done by default, open your Windows Start Menu, go to Control Panel | System | Advanced System Settings | Environmental Variables, and click Edit on the Path variable within the user variables for your account. Click New and add the path of the folder that contains your GitHub installation.

Check whether your CLI has been installed successfully by opening your command prompt and typing git –version. If the output returns the version, that confirms that Git is already installed.

You will now have to set your GitHub credentials. Configure your username to record changes you make to your local repository with the command as follows:
$ git config –global user.name “{firstname} {lastname}”

Configure an email address that will be associated with each of your history markers:
$ git config –global user.email “{youremail}”

You now need to authorize your device to modify repositories that are owned by your GitHub account. As part of this, we need to register an SSH key. Start by generating an SSH key via the command prompt with the following command:
$ ssh-keygen -t ed25519 -C “{youremailhere}

When prompted, specify the folder to generate the SSH key to; otherwise, let the default be and change the directory into the folder that it is generated in.

Open the id_ed25519 file that is generated in a text editor of your choice and copy the contents of the file.

In GitHub, in the top-right corner, click your profile photo and click Settings.

In the Access section, click on the SSH and GPG keys.

Click New SSH Key or Add SSH Key.

In the Title field, add a label that describes the purpose of your key, such as an identifying name for the device you are linking it with. Select the type of key, which in this case is Authentication Key. Paste the key that you have copied into the Key field and click the SSH key.

Figure 1.6 – GitHub page to add a new SSH key

You should now have authorized your device to modify repositories on GitHub, so we will now be able to push code from our local development environment onto the GitHub repositories.

Leave a Reply

Your email address will not be published. Required fields are marked *