Git Basics Part 3

So far, In my git tutorials, I’ve talked mostly about version control on your own machine. With this last tutorial we will be moving to Github to store and keep a backup of any git repository you have. Github has some amazing tutorials to guide you through putting your git repository on Github, so they are a great resource if you are ever confused about Github or even git in general.

The first step in using Github is to create a Github account and a repository. Once you have your repository set up, you can go ahead with the default settings. Leave ‘Add a readme’ unchecked, if you already have a git repository on your machine. Once your repository is created, you should be able to find a link in this box, pictured below.

Copy that link, and paste it into this git command to link up your repository and the repository on Github.

onionchesse@hunger:$ git remote add origin <Github URL>

Leave the angle brackets out when copying in the url! If that goes successfully, you now have linked your git repository with the one on Github! You can issue a ‘git push’ to upload a change to Github. If you decide to make a change online, such as through the Github web UI, you can bring those changes into your repository on your computer with the ‘git pull’ command! It really is that simple. But yet, it isn’t.

The reality is that git is an easy to use program with very hard to use features embedded inside of it. Branches, Pull Requests, Rebases, and Merges are all advanced features that you should understand before actually attempting. You already did a great favor for yourself by learning the command line interface, which is really the only true way to learn git internals, to actually understand what it is doing. The first time you get a ‘merge’ conflict can be a frightening one, but that simply means that git wasn’t able to combine two commits (one from online, and one from your computer) without overwriting code! There are many tools online for fixing merge conflicts.

All in all, I wish you good luck with git, but with these guides, you should be well set off with the basics of git, enough to manage your own files from time to time! Take care, and don’t forget to commit!

– [onion] chesse


Git Basics, Part 2

As I talked about last week, git is a extremely powerful version control system, mainly used for archiving code. Lets start to understand git, by plunging in and creating our first repository! Lets first create our repository by creating an empty folder in the command line, and cd’ing inside of it.

onionchesse@hunger:$ mkdir GitRepo
onionchesse@hunger:$ ls
onionchesse@hunger:$ cd GitRepo
onionchesse@hunger:$ ls

The output of the last command is nothing, as there is nothing inside this new folder. Lets turn this folder into a git repository with the ‘git init’ command.

onionchesse@hunger:$ git init
Initialized empty Git repository in ~/GitRepo

Cool! Everything inside this folder will be version controlled from here on forth, in the form of commits. The most useful command that you can learn with git is ‘git status’. It will tell you about the current status of the git repository, such as untracked files, changes not committed, and other problems.

onionchesse@hunger:$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)

As you can see, git is telling us there is ‘nothing to commit’, or no files to track. Lets start by creating an empty test file with ‘hello world’ inside of it:

onionchesse@hunger:$ echo 'Hello W0rld!' > test
onionchesse@hunger:$ ls
onionchesse@hunger:$ cat test
Hello W0rld!

Now we have a file that we can version control. In git, you have to add files to a ‘staging’ area before you can commit them, to prevent git from tracking unwanted files. Lets add this file to the git repository and commit it! (By the way, the -m flag adds a message to the commit, to help you keep track of commits.)

onionchesse@hunger:$ git add test
onionchesse@hunger:$ git status
On branch master
Initial commit
Changes to be committed:
 (use "git rm --cached <file>..." to unstage)
 new file: test
onionchesse@hunger:$ git commit -m 'My First commit!'
1 file changed, 1 insertion(+)
create mode 100644 test

And now we have a file that will be version controlled in the future! Lets make a new version by changing it, then recommiting!

onionchesse@hunger:$ echo 'Hello World is for noscopers' > test
onionchesse@hunger:$ git add -u
onionchesse@hunger:$ git commit -m 'Next Commit.'
[master 746f282] Next commit
1 file changed, 1 insertion(+), 1 deletion(-)

The -u flag to add is extremely useful! It adds all files that have been changed. This DOES NOT add new files, however. Lets prove that git is actually keeping versions, by showing history, differences and reverting back to that first commit.

onionchesse@hunger:$ git log
commit 746f282f549b76ad8cff8a7f7bac76576cb47c50
Author: onionchesse <>
Date: Fri Oct 24 23:22:21 2014 -0400

 Next commit

commit 0866cdda0d3bd822b96addf5b0221063f4482f3a
Author: onionchesse <>
Date: Fri Oct 24 23:19:53 2014 -0400

 My first commit!
onionchesse@hunger:$ git reset --hard 0866cdda0
HEAD is now at 0866cdd Next commit
onionchesse@hunger:$ cat test
'Hello W0rld!

The reset command reverts the entire history of the repo back, to a specific version. The –hard flag tells git to overrwrite all changes, to go back to how it actually was at that revision. The string at the end is the version number, which you can spot (the start of) in the output in git log! It sometimes is difficult to remember actually what happened in each release. You can find the differences with the ‘diff’ command. Lets revert back to that second commit and try it out.

onionchesse@hunger:$ git reset --hard 746f2
HEAD is now at 746f282 Next commit
onionchesse@hunger:$ git diff 0866cdda0
diff --git a/test b/test
index 1b63bde..eb9b174 100644
--- a/test
+++ b/test
@@ -1 +1 @@
-Hello W0rld!
+Hello World is for noscopers

The git diff takes in a version number to compare to. As you can see, between these two versions, ‘Hello W0rld!’ was “subtracted” and ‘Hello World is for noscopers’ was “added”. This continues to work across many version numbers as well.

If this doesn’t seem to useful, its about to get extremely useful in Git Basics Part 3, where i’ll talk about collaboration between developers, and branches! In the meantime, practice using git in this simple way! Maybe github may start to make a little more sense than your first time looking at it…

– [onion] chesse

Git Basics, Part 1

Suppose you are using a computer, like you are doing right now. You probably use it most of the time to browse the web, but you also use it to create content. Suppose you are working on an essay, for example. Have you ever been in a situation where you were creating that essay, and you thought, ‘I wish I could just go back to how this essay was before today?’ No? How about that one time where you accidentally deleted all the files on your flash drive… Interested now? Git and its remote service, Github allow you to solve these problems in an extremely elegant fashion, by keeping track of versions whenever you tell it to. This has helped programmers around the world to collaborate on projects, independent of how well they know the developer!

Git is a very complicated but useful piece of software, and fully understanding it can take years of experience. However, this does not stop one from using it productively! To get started on windows, you can install git from here. Here are some terms important for you to learn, ones that you will be using every day when using git:

  1. Commit- In its simplest form, it is a version. When you want to save a version for future reference, or for backup. This can be as simple as a single addition or a large feature set (in a program). If you get confused, read commit as ‘change’
  2. Repository- Where the things you want to version control are. It is usually a folder on your computer. When you make a commit, files from this folder will be added to the repository, and will be kept version controlled. In git, every computer involved has its OWN FULL copy of the repository. To make changes, you commit then distribute them to other members.
  3. Push- A push is where you move commits from one copy of a git repository to another copy (usually on different computers).
  4. Pull- A pull is where you get new commits from another repository, to update your copy.
  5. Branch- This is a slightly advanced concept that describes a point where commits diverge. Suppose you make a commit (change). Then you reset your computer to before you made that commit, and make a different commit. The paths have diverged between these two commits, they are on different branches. Its ok if you dont understand this, I will talk about it more later!
  6. Rebase- A more advanced concept that I will talk about later. (It requires you to know about branches).

Also, keep in mind, git works best with pure text files (like code files). It works, but extremely inefficiently on other types of files. Next week, we will start with creating your first git repository, making a commit, and saving your code (or text) up on github!

– [onion] chesse

Software Licenses

We live in a very interesting world, which all work is kept under control of the creator. Many people (mostly corporations), say this is a good thing, and actively work to extend copyright control. Currently, the life of copyright is well past the life of the creator himself. If one makes a more thorough evaluation, one finds that copyright actually inhibits the growth of new content. In a way, all new content builds on old content, from Disney movies, to artwork, to pieces of software. This last example is an interesting one, as all pieces of software share certain similarities. After all, there are only so many was to write a sort, algorithm, or search. This has lead software into becoming a grey area for a lot of copyright. Many people are fine with sharing their software, however, and want to put their software out there for others to hack on, and a software license will allow people to do that. To use a license, people can simply include the license with the source and the binary files, to show users what rights they have. There are many different types of software licenses, and here is a quick sampling of the most common ones.

The following information is not a substitute for the actual license. For more information, read the full legal text of each license.

The MIT License

The MIT license is probably the easiest to understand: It lets users do anything with your code, as long as they don’t sue you. Large projects don’t use this license too much, as it gives the user absolute freedom to do whatever they want with your software, such as distribute it at a cost or rebrand and redistribute it. It’s a good choice for those who just want to publish a small project to the world, and don’t care about what happens to it whatseover.

The Apache License

The Apache license is very similar to the MIT license, and is used by Apache Free Software projects, such as Hadoop and Apache Web Server. The major differences are that the Apache License gives away Patent rights, and forbids the use of trademarks in derivative software. Use this if you are concerned about the previous two key differences. If you are looking for an alternative, the BSD license might work for you as well!

The Mozilla License

The Mozilla License is used by Firefox and other Mozilla products. It adds a few more restrictions on the more permissive licenses, by requiring that the source must be disclosed with all future derivatives. This prevents companies from using the program within their software suite (and selling it), without giving away the free source and the binaries of the original program.

The GNU General Public License

The GNU License applies even more restrictions by saying that future derivatives or works that use the software must be licensed with the GNU GPL or other free software licenses. This license prevents other companies from using your software in a situation where users are denied the freedoms that you give them in your license, which furthers the open source software movement. However, this can be a downside for people who want their work to be used in proprietary situations, such as most commercial ones. All GNU projects are licensed under this license, such as gimp, gcc, and almost all utilites found in a GNU/Linux system or a GNU Operating System.

– [onion] chesse

I/O Redirection and Pipes

One of the true powers of the shell is the ability to pipe and redirect input and output. With these two tools, the huge amounts of small tools that bash provides can be combined together into complex programs that would be hard to create otherwise.

In the simplest terms, a pipe is moving data from the output of one program to the input of another. In order to fully appreciate this concept, I must introduce two new commands: echo and grep. Echo simply prints its argument out on the command line, and grep is a search utility.

onionchesse@hunger:~$ echo -e "Hi!\nKittens are fun\nI like to eat onions\nAnd chesse"
Kittens are fun
I like to eat onions
And chesse

In this command there are two new concepts, arguments and newlines. The ‘-e’ on the command is the argument. In this case, the presence of the -e tells the command to enable ‘escape characters’ which allow us to put tabs and other hidden characters in the output. The ‘\n’ in the command is a ‘newline’, a character that ‘moves the cursor’ down a line. It causes the output to be printed out on multiple lines!

Now that we see how echo works, lets see how to use grep, to search for ‘chesse’

onionchesse@hunger:~$ echo -e "Hi\nKittens are fun\nI like to eat onions\nAnd chesse" | grep "chesse"
And chesse

Hey look! only the ‘And chesse’ line got printed out! Lets examine this  a little closer… The ‘|’ character is a ‘pipe’, it will send the output of the ‘echo’ program to the input of the ‘grep’ program. The grep program will then block any lines not containing ‘chesse’, as that is what we told it to search for. What if we only want it to print out ‘chesse’, instead of the entire line? We can use an argument to the grep command to do that!

onionchesse@hunger:~$ echo -e "Hi\nKittens are fun\nI like to eat onions\nAnd chesse" | grep -o "chesse"

The ‘-o’ argument tells grep to print ‘only matching’ strings, which is why we only got the ‘chesse’ this time!

However, we still have no idea how to write to files! The simplest way to do that is with output redirection, or the idea of sending the output of a program somewhere besides your terminal window. Lets see if we can put the output of the echo command into a file!

onionchesse@hunger:~$ echo -e "Hi\nKittens are fun\nI like to eat onions\nAnd chesse" > foodies.txt

The ‘>’ symbol redirects the output of the echo command to the file ‘foodies.txt’. Notice how there is no output on the screen! That is because the output got sent to a file instead. Lets ‘ls’ and try to find it!

onionchesse@hunger:~$ ls
Desktop Documents Downloads Dropbox foodies.txt Minecraft Music Pictures 
onionchesse@hunger:~$ cat foodies.txt
Kittens are fun
I like to eat onions
And chesse

The ls command clearly shows our new file, foodies.txt! We can ‘cat’ the file to find out the contents of it, and we find out what echo printed out earlier! However, the ‘>’ operator is dangerous, in that it overwrites any files already with the same name. We can prevent this with the ‘>>’ operator, which will append to the file instead! Lets go ahead and try it out on foodies.txt!

onionchesse@hunger:~$ echo "Do I like pie?" >> foodies.txt
onionchesse@hunger:~$ cat foodies.txt
Kittens are fun
I like to eat onions
And chesse
Do I like pie?

And we see clearly, that our output has been appended to the end of the file! Very useful, especially when you want to send debug output of a program to someone else.

This is only a tiny fraction of what is possible with bash, and by combining more tools using pipes and redirection, you can build up complicated programs extremely easily! This takes a lot of practice, however, so play around with redirection and see what happens!

– [onion] chesse

The Shell

When I say ‘computer’, most people think of this:

However, when I say ‘computer’ to a computer expert, they think about this:

Vastly different right? Every computer expert a least has the basic knowledge of command line usage. The reason for this is that the command line is the most basic, raw, and primal way of interfacing with a computer, that allows for more complete control and higher productivity. To run firefox in a command line, you type:

onionchesse@hunger:$ firefox

As opposed for looking for an icon or searching a large list of programs (i’m looking at you windows 8!). This simplicity and powerful nature of the command line leads to huge increases in productivity. By the way, these blocks indicate snippets of command line ‘code’, which do not include the stuff before the ‘$’. So in this case, you would type ‘firefox’ into your shell.

Because of the major inconsistencies between the original (unix) and the skewed (windows) command lines, I will be talking the unix shell, which is ‘bash’ by default on most Linux, and osX machines. (Once using both enough, you will see why). Bash is a free and opensource derivative of the original command line interface, the shell (or sh). Bash stands for ‘bourne-again shell’, which is extremely appropriate, given its history. This article will cover most of the basics of using a shell.

To start your shell, just open up a ‘terminal’ program on your computer. If you are running windows, you need to install cygwin to get this functionality.

When you start a shell, you are ‘placed’ in a directory on your computer. Think about opening a file explorer in windows, or finder on a mac, you are pointed at a location on your computer, like my documents or my programs (in windows). To find out where you are on your computer, type ‘pwd’:

onionchesse@hunger:~$ pwd

That output, the ‘/home/onionchesse’ is the current directory, or where I currently ‘am’. I can find out what files are in this location by using the ‘ls’ command:

onionchesse@hunger:~$ ls
bin Copy Desktop Documents Downloads Dropbox Minecraft Music Pictures Public Templates Videos

Hey, there are all my folders which are inside that ‘current directory’. Lets now try moving around! To move around, we use the ‘cd’ or change directory command:

onionchesse@hunger:~$ cd Minecraft
onionchesse@hunger:~/Minecraft$ ls
MagicLauncher_1.2.5.jar Minecraft.jar Mods TechnicLauncher.jar

The cd command moved us into the Minecraft folder, and ls listed the contents of the Minecraft folder, which has some cool jar files! (Pro Tip: You can press tab when typing out a directory name to autocomplete it if the name is unabiguous! Ex: ‘cd Mine<tab>’ completes to ‘cd Minecraft/’). Typing out ‘cd ..’ will take you back ‘up’ a directory, and typing ‘cd ~’ will take you to where you started! (This is called the ‘home directory’ on unix machines, and it is represented by the ‘~’). These little shortcuts add up until you can save yourself a ton of keystrokes.

Lets now create a text file! The ‘touch’ command creates a text file:

onionchesse@hunger:~$ touch MinecraftIsAwsome.txt
onionchesse@hunger:~$ ls
MagicLauncher_1.2.5.jar MinecraftIsAwsome.txt Minecraft.jar Mods TechnicLauncher.jar

Hey! MinecraftIsAwsome.txt showed up! Lets see what inside it! The ‘cat’ or concatenate command will print out files (as text) to the command line:

onionchesse@hunger:~$ cat MinecraftIsAwsome.txt

Oh no! Nothing got printed out! This is because there was nothing in the text file to begin with… We need to fill that text file with information to print out. Next week, i’ll talk about i/o redirection, which will allow us to easily write to files from the command line! In the meantime, open up Notepad, Word, or Microsoft Paint and edit that file the way you’re used to. Just make sure to save as a text file!

-[onion] chesse

A Tale of Software

Due to the apple unveiling event taking place tomorrow, I have decided to stray from my usual topic and talk a about the commercialization in software! This will also give insights into my future posts.

Last post, I talked about how computers had become tainted with overuse, and how all computers became poorly maintained over time. This is mainly due to the commercialization of software. In the beginning, only experts could use computers. One of the main reasons for this was the command line, a prompt where you would type commands to do everything on a computer. To use it, one had to remember commands, parameters to those commands, and pay a penalty for any mistyped commands. It was easy to ‘brick’ an entire system with a typo on the command line. With the invent of the graphical user interface (or GUI), a new era of computing started.

Now, suddenly, it was extremely easy to use a computer! One could simply click on a icon to run a program, rather than having to memorize commands. One could check boxes instead of memorize command line arguments! And most importantly, confirmations were added, to reduce the possibility of breaking your system.

Naturally, this kind of computing exploded, as literally anyone had access to the power of a computer, with no training. The corporations that developed these GUI’s exploded into the giants that we know today: Apple, and Microsoft. The command line, at least in windows, was a shunned tool, thrown away like a old sock. Computer ‘Experts’ became those who knew what all the little buttons do, instead of those who had spent years learning about the internals of a computer. The ‘stupid user’ became someone who had literally no prior experience with technology, maybe forced into a computing job. All possible because of the GUI.

However, the GUI gave companies the power to lock its users in. All the users had no idea about the internals of a computer, they ‘just wanted to get work done’. So naturally, the GUI’s constricted, giving less and less of those options that were needed by the true professionals, as the target audience was those who had no idea how computers work. Recently, the corporations have taken it even farther, by essentially forcing certain mandates on its users. Windows has many ‘features’ that limit a user’s freedom, from having the power to delete programs on its computers, to sending information about usage back to Microsoft. Apple actively fights users who are trying to gain freedom, by voiding warranty on ‘jailbroken’ products, limiting apps on the app-store, and placing backdoors in products available to Apple itself, giving them almost full control over every apple product. Of course, the users don’t care… They just want to ‘use a computer’. The professionals who were around before this revolution are warning of the consequences to accepting these products, but very few people are listening, as no one simply cares. All who ‘disagree’ are either ignorant to these changes being ‘marketed’ to them in plain sight, or are willing to trade usability and ease of use for their freedom.

In order to truly learn about computers, you need to bypass the restrictions that corporations put on you, so you can have full access to the wonderful machine you own, and the only way to do that is by utilizing free software. Because of this, I will mainly be showing you how to use free software, rather than proprietary alternatives, because proprietary software simply limits what is possible for a computer to do.

When you go down to the apple store and attempt to get that iPhone 6, think about how much freedom are you willing to give up. Do you even have the freedom to abstain from buying the new iPhone? Or are you just digging yourself a hole of reliance from which you have no possibility of escaping…

-[onion] chesse


The Computer

Once, Computers were a tool reserved for the very elite. They cost many thousands of dollars, were the size of a room, and required constant care to run properly. To use a Computer you would need to learn about every aspect of how a Computer would work. This fact, in combination with how catastrophic a simple error could be, lead to every Computer being extremely well maintained. Now, the only Computers that are maintained as well as those from our past are those of companies, who pay system administrators to take care of, use, and oversee use of a server…

With the rise of ‘easy computing’ came the rise of the famous, at least in IT, stupid user. Nowadays, anyone from any background can ‘use a Computer’, in fact, many of us spend most of our waking lives using one, be it for social media, gaming, or typing a report. Little ‘previous knowledge’ is required, unlike any other high level tool. Every tractor driver requires basic training, every pianist must learn how to play, and every machinist must learn how to use a milling machine and other tools, all processes which take years to accomplish. However, today we see even 1st graders being brought over to the ‘Computer lab’, and being told to type up essays, with little to no prior knowledge about Computers. The Computer, nowadays, is treated as a basic tool, on par with a pen, or a crowbar, but its internals are more complicated than any other gadget on the planet.

Almost every system in our age is one maintained by a person who is not a Computer expert, which means they are blind to the true power and glory of computing. They would say, “Oh, my Computer is getting slow, time to buy a new one”, or, “Any file that ends with a .txt is a text file”, or, “I need to go download some more ram“, all comments that are blissfully ignorant of the true power and capabilities of a Computer. In order to use any tool effectively, you need to learn the most effective way to use it, and how the tool works ‘under the hood’.

This blog is not for the ‘stupid users‘, nor is it for the ‘wizards‘. It is for those users who are amazed by the technology of the Computer, and willing to put in time, make sacrifices, and fix their own problems, in order to LEARN how a Computer actually works. If these people encounter an error they have never seen before, they will take the time to figure out what has gone wrong, why it went wrong, and the PROPER way to fix it.

Let us go forth, and find out what it REALLY means to check that ‘advanced users only’ box.

-[onion] chesse

DISCLAIMER: While it may appear that I know a lot about Computers, I really don’t. I just want to make it easier for people to go through what I struggled through for 4 long years: beginning to learn how to truly use a Computer. My journey is nowhere near complete, but I hope to help the few of you that will stick with me to get started and broaden everyone’s mind about The Computer!