Blog logoThe Open Source U


Fundamental open source software concepts that you should become familar with.

Bit Masks

 •  Filed under OSS, oss-concepts, computer science, reference, quick-tip

Bit masks are a computer science concept; in a nutshell, they represent options which can be combined in a variety of ways.

A very basic example colors. Blue and Green combined create yellow. This can be represented in bit masks.

The following example is sourced from the Bit field article on Wikipedia; it illustrates the concept well for those new to it.

Consider the following1 and take note of the binary version which is in the comment.

// primary colors
#define BLUE  4  /* 100 */
#define GREEN 2  /* 010 */
#define RED   1  /* 001 */

This creates the base options. The next example uses the above to further define more colors without assigning them specific numbers, although they would output as numbers.

// mixed colors
#define BLACK   0                    /* 000 */
#define YELLOW  (RED | GREEN)        /* 011 */
#define MAGENTA (RED | BLUE)         /* 101 */
#define CYAN    (GREEN | BLUE)       /* 110 */
#define WHITE   (RED | GREEN | BLUE) /* 111 */

Notice that WHITE is all the colors -- all the bits are "on" and black is no color -- all the bits are off.

I've seen this used quite a bit although, I must admit, I don't come across it quite as often as I used to. Rest assured, it is still in use and is quite useful.

  1. The code presented is Pseudocode. It is not intended to be complete.

Using git to Contribute to OSS

 •  Filed under OSS, oss-concepts, GitHub, git

There are plenty of resources out there to learn how to use git... but I'd say a good percentage of those focus on using git from git init and on -- that is, starting a new repository from scratch.

This post is going to focus on using git to contribute to an existing, established project on github. I'm assuming no prior knowledge of git/GitKraken/SourceTree. That said, I'm going to assume you are using at least GitKraken or SourceTree and not the CLI.

Example Project

I encourage you to follow along. For my screenshots, I'll be using my "pg-migration" project but you can use any GitHub project you desire. I strongly encourage you to follow along.


Lets Go

Open the "project" for GitHub. You want to fork the target repository. What this does is create a copy of the project to your GitHub account. This becomes your "remote working" space.

Fork button on GitHub

Upon clicking this, you see something like the following.

Processing screen on GitHub

After the process, you'll be taken to the forked instance which will appear quite identical to the original. For example, the readme will be showing.

At this point, you clone the repository with git. Cloning is similar to check out used in TFS or Subversion; there is more to it but for now consider them the same thing. You want to clone your fork and not the original in order to be prepared to publish changes for a pull request later.

Getting the clone address

With GitKraken, there are several ways to close a repository but the most direct are to select File -> Clone. You'll be presented with a dialog like the following. You may use the URL option or the option. For simplicity, I'll show a screenshot of the URL section.

Cloning in GitKraken

Once you've cloned you'll be on the default branch master, before doing anything you should create a branch specific to your current efforts. The common branch naming convention is:

  • feature: feature/feature-name-or-id
  • issue/bug: issue/issue-id
  • explore or hacking1: hacking

Branching in GitKraken

Click on "branch" and enter a name for it and hit enter. If you're just doing the steps to follow along, use hacking as the branch name otherwise select accordingly. Upon creating the branch, your working copy will be set to the branch. The working copy is the source code that you can edit.

If you open the folder in Finder or Windows Explorer, you should see the source files as, well, files.

In GitKraken, the active branch has a green checkmark next to it.

Active Branch

You are now ready to work. You can put comments or make changes. If you want to keep the changes, commit them. When you commit in git you are only committing to your clone -- that is, the git repository on your computer. Git works by keeping a full copy of the version control repository locally. There is a complete copy on the server as well but the two are only indirectly linked -- you have to give it the push command to send the changes to the server.

Consider the git repository on your computer to be temporary. Any changes you want to truly keep should be "pushed" to Github. This makes hacking in a throwaway branch on your local repository super easy but it also means that you can lose work you want to keep. Be mindful of this and push when appropriate.

Make a few changes or add notes for yourself -- anything really -- and save the modification. Let's commit these changes. In GitKraken, the command becomes present when it detects changes to your working copy. Select the line that says // WIP and you'll see something like the following. Note that the UI changes layout depending on the size of the window.

GitKraken Commit UI

Move your modified files to staged -- this indicates your intent to include these files in your commit -- fill in the summary and click "Commit".

The UI updates to reflect that hacking has moved forward one node from master and you'll see your notes. From here, I encourage you to explore the UI of GitKraken or SourceTree.

Once you are ready, I encourage you to push your changes to the repository on GitHub. Remember that you forked the project and so:

  1. You have write access to the repository.
  2. Changes to your forked repository are not going to affect the source project.

Click the push button in the toolbar and you'll be presented with the following dialog. Simply click Submit.

GitKraken Push dialog

This dialog is indicating you're going to send this to the remote called origin (automatically assigned to the clone source) / branch hacking.

On the GitHub side of things, you'll see the following:

GitHub after the push

Should you want the author of the source project to include your changes in the main project (and assuming you've followed the project's contributing documentation), you can issue a pull request.

For now, that is the basic usage of git to collaborate on an existing project. There are other things you need to be aware of such as merging and overall branch management but I'll be covering those in future articles. For now, this should get you started.

Enjoy hacking.

  1. I've invented this. It's a convention I use to avoid contaminating master.

What is a Pull Request?

 •  Filed under oss-concepts, GitHub

A pull request is an important concept in collaborating with others' on GitHub. When you finish work and you want to share it with the project's owner, you issue what is called a "pull request".

This is you asking the project maintainer to review your contribution and pull it into the main git repository. Each project has their own requirements in order to accept the pull request.

Please see the contribution documentation for your target project for details.

What is a ""

 •  Filed under OSS, GitHub, quick-tip, oss-concepts

In most established open source projects, you should find some sort of information regarding contributing to that given project. This could be called or or is simply a section in the repository's Readme file.

If you intend to contribute to a specific open source project, ensure that you follow that projects' "contribute". Most project maintainers won't accept your pull request unless you do.

For example, here's the contributing guidelines for Nightwatch -- a project I hope to cover in the near future.

Here's a subset of their document with regards to submitting a pull request:

  1. Follow the usual git workflow for submitting a pull request

    • fork the project
    • create a new branch from master (e.g. features/my-new-feature or issue/123-my-bugfix)
  2. If you're fixing a bug also create an issue if one doesn't exist yet
  3. If it's a new feature explain why do you think it's necessary
  4. ...
  5. ...
  6. Do not include changes that are not related to the issue at hand
  7. Follow the same coding style with regards to spaces, semicolons, variable naming etc.
  8. Add tests - after all this is a testing framework