A short introduction to GitHub

No readers like this yet.
GitHub logo with navy background

From GitHub

Summary of All Things Open 2015 session with Lee Faus, GitHub 101: An introduction

I am on GitHub and have committed the Koha manual to our git repository, but I'm not sure how to use GitHub to it's fullest capabilities, so I was excited to attend Lee Faus's introduction to GitHub. For those who don't know, git is a distributed version control system; this means you can work locally without having to commit back to the repository every time. It means that developers can work locally until it's time to "push" their changes to the version control system. So, you can experiment a lot more while using git because you're working on your own local system.

Installation and configuration

Git is preinstalled on all Mac and Linux computers; you might have to patch it, but it's there. If you use Windows, then you have to install it. You can also use a tool like GitHub Desktop and/or Tower for Mac.

The most important step is to configure git:

$ git config --list

This will show your identity and your settings for your machine. Using git config, you can set up git so that you can have multiple identities in git. Maybe you have your global identity which is your company profile, but maybe you also want to user your personal identity, this is when you use your local identity.

$ git config --local user.name [name]
$ git config --local user.email [em]

Creating a copy

Next, grab a copy of the repository you'd like to work on. When using GitHub, see the clone URL on the menu on the left of the screen. Then you can clone a copy to your machine:

$ git clone [url]

This will create a folder structure on your system that matches the git repository on GitHub.

GitHub tip: When in a repository, if you hold down your 't' key, you will be brought to a search where you can type a filter to find files that have names that match your search. Because GitHub is a text editor, you can easily make simple changes in the browser and commit it from there.

Before making changes it's good to work in a branch:

$ git branch feature/add-subtraction
$ git checkout feature/add-subtraction

This will create a new branch, and then you can 'checkout' the branch so that you're working on that branch instead of the 'master' branch. This gives you the opportunity to iterate on your code locally so you can work without the stress of messing up on the main branch. If you end up breaking things you can just scrap your branch and create a new one based on the working master branch.

Make changes

See what files you have changed by typing:

$ git status

You can then commit your changes by entering:

$ git commit src/main/java/com/github/Calculator.java -m "added subtraction"

This commits the changes in the sandbox with a message of 'added subtraction'. It's important to remember that this change is only on your local machine and you have to 'push' this change to be able to see it on GitHub. To push the change, enter:

$ git push origin feature/add-subtraction

Now you will see a new branch listed for the subtraction feature you've added. Finally, if you want to get this in to the master you will need to submit a 'pull' request to get your branch pulled in to the master.

Pull requests can be done right in GitHub to start a conversation around this code and feature. There is a ton more you can do with GitHub, but this Lee's talk was a great introduction, and now I'm ready to start playing with some new projects!

All Things Open
series

This article is part of the All Things Open Speaker series. All Things Open is a conference exploring open source, open tech, and the open web in the enterprise.

User profile image.
Nicole C. Baratta (Engard) is a Senior Content Strategist at Red Hat. She received her MLIS from Drexel University and her BA from Juniata College. Nicole volunteers as the Director of ChickTech Austin. Nicole is known for many different publications including her books “Library Mashups", "More Library Mashups", and "Practical Open Source Software for Libraries".

2 Comments

I'm not sure what distributions this article is referring to, but I know that in netinstalled Debian distros with Desktop environments (Gnome3,KDE,LXDE,XFCE and MATE) the git package is not installed by default. So the statement that git is installed by default must be clarified; it applies only for customized distributions geared for software development.

Thanks for clarifying that!! I don't know for sure either which distribution was being talked about.

In reply to by Dimitris Anogiatis (not verified)

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.