blog
blog copied to clipboard
Setting up, cloning and pushing from your IBM i to GitHub
What you will need:
- Sign up to GitHub, now. You can find the BitBucket method here, by Aaron Bartell.
- An editor to make changes to files on the IFS. For example, Rational Developer for i, Notepad++ with NppFTP, Orion or local machine connected to IBM i share.
- 5733OPS, option 6 - e.g. Git. (2019 update: install git through yum)
- Setup an SSH key (read below)
Setting up your SSH key
An SSH key is a passphrase. You generate it on your IBM i, then upload it to GitHub. Then whenever you interact with your remote repo, it authenticates by making sure these keys match. Do not share your key.
Start an SSH session (ssh [USER]@[SYSTEM]
) and follow these steps. Where [USER]
is, use your IBM i user profile name.
-
> mkdir /home/[USER]
-
> cd /home/[USER]
-
> ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/[USER]/.ssh/id_rsa):
Created directory '/home/[USER]/.ssh'.
Enter passphrase (empty for no passphrase): [ENTER]
Enter same passphrase again: [ENTER]
Your identification has been saved in /home/[USER]/.ssh/id_rsa.
Your public key has been saved in /home/[USER]/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:EjLLnXBpN/+TQ55RnOP1xjWfpf5qQYSPem9BsVYGxo4 [USER]@swagibmi
The key's randomart image is:
+---[RSA 2048]----+
| oo. |
| . .o+.o|
| + = o *=*+|
| . O + o EoB=B|
| o + S ..o+o.=|
| . .+.=o. |
| .B..o |
| o+. |
| o...|
+----[SHA256]-----+
So now we have an SSH key stored at /home/[USER]/.ssh/id_rsa.pub
. We need to copy the contents of this file onto our GitHub account.
- To get the contents use:
> cat /home/[USER]/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCo1By2F0CT3d8LEm9TuS7+qofMaZOI/4cLS8/38o...
- Log into your GitHub account and navigate to your account settings.
- Select SSH and GPG keys from the bar on the left.
- Hit the big green 'New SSH key' button. A new section should appear in which you can provide a title and the SSH key which we created earlier.
- Give your key a name and then paste in the key we saw earlier - I suggest the name is the same as the IBM i system you're using.
- Click 'Add SSH key' and you're done.
Git user setup
You will need to setup your local Git profile to have a name and password. Simply use these commands, but replace the values in speech marks:
> git config --global user.email "[email protected]"
> git config --global user.name "Your Name"
Cloning some RPG.
Select a repo you want to clone on GitHub. For this example, I will use DB2GET. To clone, you will need to close 'with SSH': open the repository on GItHub and click 'Clone or download'. Copy the SSH link that this window provides.
Use this link to close the repository, like so:
> git clone [email protected]:WorksOfBarry/DB2GET.git
Cloning into 'DB2GET'...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 15 (delta 2), reused 15 (delta 2), pack-reused 0
Receiving objects: 100% (15/15), done.
Resolving deltas: 100% (2/2), done.
You may be presented with this, but just take the 'yes' option.
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Compiling RPG from the IFS
This piece is specific to DB2GET. Obviously each project is different!
Now you have a Git repo in your home directory, it's time to compile the program provided. To do this, I will use Rational Developer for i.
- Open RDi and connect to your system. Browse down to your repo on the IFS.
- Right click 'DB2GET.sqlrpgle', select Compile->CRTSQLRPGI and wait for the compile to happen.
Now the program is compiled and you can do what you want with it!
Making changes, committing and pushing
Next, you can open your editor and making changes to the IFS source. As you make changes, don't forget to compile and make sure your programs work before you commit anything. To save time, you can see what changes I made here:
Now, let's see what files have changed and commit the files. Back into your SSH session:
-
cd DB2GET
to change directory into your local repo. - Use
git status
to see what files have changed.
> git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: DB2GET.sqlrpgle
no changes added to commit (use "git add" and/or "git commit -a")
-
git add --all
to add all modified files to the index before the commit. You can optionally usegit status
to see that the files have been added. -
git commit -m "[COMMIT_MESSAGE]"
to make a commit to the local repo, where[COMMIT_MESSAGE]
is your commit message.
> git commit -m "Add DSPLY output"
[master 01eba1e] Add DSPLY output
1 file changed, 3 insertions(+)
-
git push
to finish and push the code back up to the remote repository on GitHub.
> git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 376 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:WorksOfBarry/DB2GET.git
78c040e..01eba1e master -> master
And that's it! You've now made a change, commit and push. You can see the change that I made for this example here.