Yes, I can imagine you’re asking yourself, “another GIT guide, what is he thinking?”  For me it means I have a source of information explained in my own words.  After finding a lot of duplicate answers on different blogs I came to a conclusion of people documenting solutions in their own words.  In the context of this article, I will explain what I know about GIT and GITHub providing a short guide for using it alone as well as using GIT with others.

What is GIT (my version)?
Confusing right?  Think of it like this:  You are a web developer, and you work with another developer and a boss.  You both are making changes to a website and do not want to overwrite each other’s work and your boss wants to review the changes before they go public.  Oh by the way, you want to be able to do this quickly, along with tracking your work and not only prevent things from being overwritten but you also want to make sure you and your coworker have a fully stored local copy of the site so you can make changes Ad Nauseam.  That’s where GIT comes in, and does even more.

How does it work?

For the sake of argument I’ll use GITHub as our example but there are plenty of other sites and services that you can use for versioning and workflow

GIT Started

First, get familiar with the following terms:  Repository, Fork, clone, branch, master.  Let’s start with your repository.  Your repository (aka  repo) is where your code is stored.  When you go to someone’s site (or your own), you will see an overview of the most popular repos, a page that will show you all of the repos, and their public activity.  The last one will show you things the user has committed to not only their repos but others they recently contributed to.

ssh-keygen -t rsa -b 4096 -C "<email address>"

ssh-add <private key name>

So if you have not already created an account on GITHub, you will need to do so. For the sake of brevity I will assume you have already done this.   Next, go to your profile settings, and add the ssh public key (the one with .pub) by copying and pasting the public key.

Basic GIT usage (single player)

git init: create a repository locally
git clone <repository>: copies a repo locally
git fetch: updates content in a repository
git status: current status of code, branches, etc
git add: stages the files for commit
git commit -m "comments": makes a commit
git push: pushes commits from local to remote
git branch <branch>: creates new branch
git checkout <branch>: switches to branch

More GIT usage (multi player)

Since I’m not a software developer by trade but do have a few friends in the community that are either learning to code for roughly the same reasons I am I don’t have as many pull requests.

I decided to save some time and write a simple bash script.  With this it implies I’m working on my own code and pushing changes to my branch.

#!/bin/bash

echo Making commit

git add <file name(s)>
git commit -m "comments"
git push --set-upstream origin <branch name>
git status

echo "Commit Finished on $(date)"

So rather than type that in every time, I just saved the script above as commit.sh, and run it in the repo folder.  That’s usually how this stuff starts.  Interesting enough, I had a couple more GIT related situation where this came in handy.