Git to Github

by | Oct 10, 2017

Originally published: IT Jungle on 3/03/2015

Updated author notes: The GitHub.com interface is always changing so please be cognizant of that when navigating their site as it relates to the screenshots in this article.

In the [last article] the git tooling was introduced as a mechanism to track changes made to source code. This article expounds on that by showing how to make your local IFS git repository (“repo” for short) publicly available to others. I say “publicly” because that is the purpose of this article, though it could just as easily be applied to a situation where you wanted a private repo for a specific set of users (i.e. co-workers, and/or consultants). For the purposes of this article we will be walking through setting up a GitHub.com public repo. Note, GitHub is the largest open source website in the world since about 2011 (beating out the likes of sourceforge.net).

First head over to GitHub.com and create an account (free and easy, so I won’t be documenting the process). Next we need to setup SSH key-based authentication between your IBM i machine and profile, and your newly created GitHub account. SSH keys are a way to authenticate without the need for passwords, which can speed up software development without sacrificing security.

They way SSH keys work is you need to generate a key on your IBM i that can then be input into your GitHub account. To generate a key you will need the no charge license program 5733SC1 IBM Portable Utilities for i5/OS *BASE & Option 1 which includes the ssh-keygen command.

From the command line do CALL QP2TERM (to get into a PASE shell) and run the ssh-keygen command, as shown below. You will be prompted for a passphrase for the key being created. You can enter one or leave it empty. You can recreate it later on with a passphrase if you leave it empty for this tutorial.

If the .ssh directory didn’t exist in your /home directory it will be created. What will also be created are the id_rsa and id_rsa.pub files, as shown below.

The id_rsa.pub file’s contents is what we need to copy and paste into the newly created GitHub account. Use the cat command to display the contents to the screen or open the file with the editor of your choice. I masked the below with x’s so I don’t expose my key to the world.

Now go to your GitHub account and click the cog icon (a.k.a. settings) so we can add the SSH key we generated in the previous step.

Viewing GitHub settings

Viewing GitHub settings

Once on the settings page select the SSH keys tab, then select Add SSH key, then enter the Title and Key, and finally select the Add key button.

Adding SSH key

Adding SSH key

At this point your IBM i is setup to communicate with your GitHub account and the next step is to create a GitHub repo that we can place our IFS code into.

Using the below screenshot, start the process of creating a new GitHub repository.

Creating a new repository

Creating a new repository

On the next page you will be presented with the below form where you will specify the name of the repository and whether it is public or private.

Configure repository access

Configure repository access

After selecting the “Create repository” button you should be redirected to a page declaring the full URL path and also some handy commands showing how to push an existing repository, which is our situation, to GitHub.

Quick setup

Quick setup

Now go back to the PASE shell session on your IBM i (i.e. CALL QP2TERM) and cd to the folder containing the git repo created in the [last article], as shown below.

Next, copy and paste command “git remote add origin…” from the GitHub page onto the command line and run it, as shown below. This declares the remote GitHub repo to our local repo so that when we do a “push” it will know where to push it to. If you’d like you can use the git remote -v command to get a listing of existing remotes.

The last step is to “push” our local commits to the remote GitHub repo. This is done with the git push command, as shown below. Notice how we weren’t prompted for authentication? That’s the SSH key at work. Since we only have a single remote repo that we are connecting to the “-u origin master” portion of command git push is somewhat redundant. It is essentially declaring the name of the remote repo, origin, and the name of the branch to push to, master in this case. Uses for git branches will be covered in a future article, but for now you can read more about them here.

As we can see from the above log everything successfully made it to the GitHub repo, and we can prove that by bringing up the itjungle_4_git repo in the browser, as shown below.

Viewing GitHub repo

Viewing GitHub repo

Clicking on the “commits” link allows you to see how the code repo has changed over time in visual fashion (i.e. what files and lines within), as shown below.

Viewing repository commits

Viewing repository commits

And here we see the changes that took place in a particular commit. Very nice!

Viewing details of a specific commit

Viewing details of a specific commit

As I mentioned at the end of my last article, we are only touching the tip of the git ice-burg. Git has many features and is flexible because it has to be – it manages entire operating systems of source code (the reason for it’s creation by Linus Torvalds, the primary creator of the Linux operating system). Play around some more on the GitHub site by exploring “Issues” and “Forking” – two features that have brought about the term “social coding”.

Stay tuned for more articles on Ruby and the Rails web framework!

RPG-XML Suite

  • Call web APIs from RPG
  • Process XML and JSON
  • Offer web services

Litmis Spaces

Affordable IBM i cloud hosting

CyberSource Toolkit for i

  • Process credit cards from native RPG
  • Integrate CyberSource payment services

Follow Us

Need Git training for your IBM i developers? Let’s chat.

  • This field is for validation purposes and should be left unchanged.

Get Social

Share to your favorite social platform