Hacktoberfest and ServiceNow Dave Slusher

4 minute read

After Your Pull Request is Accepted

Last week we posted information on how you can use ServiceNow projects to participate in Hacktoberfest. This involves some work server-side for the maintainer to be able to emulate the merging of GitHub pull requests. Let’s say you participated, submitted a pull request and it was accepted and merged into the main repository. Now what?

GHC_Contributor_Workflow_Diagram.png

To reiterate slightly, you will have your own fork of the repository, and your ServiceNow instance is connected to your copy of the repository. The accepted pull request is now living on the original repository. While you have the work you did, it may have been altered some as part of the acceptance process and there may be other code that was committed. You have none of that. How do you get it?

Here are the steps. As of this writing, we haven’t figured out a better way than using the command line client. On your local workstation, create a folder to hold a copy of your repository. You won’t be doing any editing of this code directly, only manipulating your repository. If you are on a Mac or Linux machine you may already have the git CLI client installed. If you need it, you can get it here.

pastedImage_1.png

Step 1: Clone the repo to your workstation.B This will be the same URL you used to set up source control integration on your instance. When you are done, you’ll have a copy of the code locally in the directory you pulled down.

git clone

After the clone, you will have a new directory in the folder you are in. Change into that directory before the next steps.

Step 2: Find the URL to the original repository. You’ll click the same clipboard icon from the original repository (but do not clone!)

Step 3: Execute the following commands one at a time. I will explain each a bit later. Note now that this will lose changes in your repository if you have unmarked work in master. This is another good reason to do all of your work on short-lived feature branches as recommended last time.

git remote add upstream

git fetch upstream

git checkout master (or name of working branch if not master)

git reset –hard upstream/master (or name of branch)

git push origin master –force

Step 4: Load your fork via the GitHub web interface. When you have the working branch selected, it should tell you that you are even with the original fork. If it says that you are ahead or behind, then something went awry with one of the previous steps.

Step 5: From your instance, in Studio do the “Apply Remote Changes” action. This will pull down the current state of your forked repository back to the instance. At this point, you can go back to working as described in the previous post.

Explanation of Commands

git remote add upstream

Git has the capacity to have multiple named “remote” sources of code. Here we are defining a new one called “upstream”. The name is arbitrary and upstream is picked to make it obvious.

git fetch upstream

This will pull down the code from the source just configured, aka the original repository not your fork.

git checkout master (or name of working branch if not master)

This will make the branch the current working branch

git reset –hard upstream/master (or name of branch)

This will reset your repository to match the upstream repository

git push origin master –force

Take all this work and move it back to the “origin” which is your fork on GitHub.

At the conclusion of all these steps, you should see your fork as even with the original fork, and after refreshing the code on your instance then all that code should also exist on your instance. This can be a bit fiddly so if you need help, feel free to respond in the comments of this post.

Since last week we’ve had a number of forks and pull requests submitted on the Points Thing Slackbot project. This is gratifying for us and hopefully fun for the participants. On Friday, Josh Nerius (josh.nerius) and Andrew Barnes (ajbarnes) did a special Live Coding Happy Hour episode showing the work of setting Andrew up to contribute to the project. Until midnight eastern on Halloween night it is not too late to generate your four pull requests. Feel free to jump in anytime! Happy hacking and happy Hacktoberfest!


Comments