Skip to content

Using the GitHub CLI

Grey Himmel edited this page Jan 8, 2019 · 10 revisions

Getting Started

The GitHub CLI is a command line interface which interacts with GitHub's own API, and is an essential part of version management. Installation is fast and easy.

First things first, download the executable from the official git site. Click the link for your operating system, and the file should automatically download. Open it when it's done, and start the installation process.

When you reach the window with different checkboxes for components, make sure it looks like this:

Check the "additional icons," "explorer integration," and "Git LFS" boxes

After this window, the installer should ask about your default Git editor. Ignore that and just hit next. The next page will be titled "Adjusting your PATH environment." Make sure it's set to the middle option, and hit next again.

It should say "Git from the comamand line and also from 3rd-party software"

The rest of the installation process can be clicked through with the next button again, until the button changes to say "install." Hit that, and when it finishes, you're all done! Uncheck the box saying "View Release Notes," and tap "Finish."

Creating a Remote Repository

A repository is where project files are stored. They come with many useful features, including specified releases, wikis like this one, and version control. Each repository tracks any and all changes through commits, just in case you need to backtrack to a version before an issue cropped up. "Remote" means that the repository doesn't exist on your machine, and instead is reached through server calls.

The easiest way to create a remote repository, or repo, is through the GitHub website itself. First, make sure you're logged into your account.* If you don't have one, now's the time to sign up. The options to do so are at the very top of the page and to the right.

When you're done logging into your account, you'll be met with a page that looks something like this:

Repositories are to the left

Click the shiny green "New" button to create a new repository. Give it a descriptive name (maybe "My First Repository" for now; you can always change it later) and a description (if you're feeling spicy), and make sure to check the box saying "Initialize this repository with a README." What you'll have should look something like this:

Finish the repo and you'll be met with a screen like this:

  1. Your username (or, if the owner was changed, that username).
  2. The repository's name.
  3. The repo's "toolbar." The most important buttons here are code, projects, wiki, and settings.
  4. The branch chooser. We'll talk more about that later.
  5. This is where you can interact with the repository without the CLI, and where you'll get your remote token. More on that later, too.
  6. The current file's edit button. Use this to edit whatever file you've got open at the moment.

* Best Practices: Unless you're doing this at home, do this from your browser's (preferably, Google Chrome) incognito/private browsing mode. This ensures privacy and prevents others from tampering with your account.

Initializing Local Repos

Local repositories are repos that are on your machine. If you want version control without a handy website to use, and only plan to keep your code on your computer, you'd initialize a local repo and commit only to that. You also need a local repo if you plan to push code into a remote repo, as it handles staging changes and commit messages, which is why initializing locally is required.

To get started, open the file explorer and navigate to the folder you want to initialize a repository in. For this example, I'll be doing it in Documents/projects/example-repo.

Inside the folder, right click and choose "Git bash here."

Should be under the git GUI option

That'll open a shiny cool window that looks like this:

Ooh, pretty!

In this terminal, type git init and hit enter. That'll initialize a local repo in that folder, and you should see a message stating so. If you've turned on the option to show hidden files in Windows Explorer, you'll see a brand new .git folder there. That's where Git does all the behind the scenes work.

Logging In

Creating New Branches

Adding Remotes

Pushing

Pulling

Writing Useful Commit Messages