CMJ Grubb

The Quick and Dirty on Git and GitHub

I should start this post off by saying that I am no GitHub wizard. I use GitHub to track changes for my own projects. I'm not worried about branching, cloning, or merging. This is really intended for beginners or as a quick reference for one-person projects.

The GitHub Part

Setting up a GitHub account is pretty easy and straightforward, and it doesn't bear me getting into other than to say that the free tier will work for most people. Once you've created your project, you'll want to create a repository. Generally speaking, each repository will correlate with a project.

To create a new repository, click the plus sign in the top right corner of the page and select "New repository" from the dropdown. Name your repository, add a description if you like, select whether you want your repository to be public or private, and check the box next to "Initialize this repository with a README."

Installing Git

Installing Git is super easy. In Linux, it's "sudo apt install git-all" or "sudo dnf install git-all," depending on your distribution. In MacOS, run "git --version" from the terminal, and it will prompt you to install if it isn't already. On Windows, an installer is available at https://git-scm.com/download/win.

Setting Up Git

There are a couple of quick commands you need to run to configure Git once it's installed:

git config --global user.name "username"

git config --global user.email "E-mail address"

Creating a Local Copy of Your Repository

I have a directory in my home folder called "GitHub" where I keep a local copy of all my repositories, but you can put this wherever you like. Just note that copying – or cloning, in Git parlance – creates its own directory, so you don't need to worry about making a directory for each individual repository. The Git command is:

git clone https://github.com/username/repository_name

Committing Your Changes to GitHub

Once you have a local repository and you've created your files within your local repository directory, you need to tell Git that you want these files added to Git's tracking:

git add file.txt

You only have to do this once per file. Once you tell Git you want it to keep track of file.txt, it will upload any changes to that file after the next two commands are run. The first of those commands is making the commit. The -m option is the message you'll want to add about what changes you made. Please note that the -m is a required option, and it's hightly recommended you take the time to create a meaningful commit message.

git commit -m "Initial commit"

Finally, we pull the trigger:

git push origin master

The Next Time You Use Git

Now that everything is set up, using Git in future revolves around using three commands:

git add newfile.txt git commit -m "Added newfile.txt" git push origin master

Finally, there's a cool command to give you some insight into what is going on with Git:

git status

The git status command doesn't change anything, so run it anytime you like. In fact, I recommend executing it occassionally just to keep up with what's going on. You may realize that a critical file isn't being tracked in GitHub just by taking the time to check.

Home