Skip to content

Instantly share code, notes, and snippets.

@cmkoller
Last active August 29, 2015 14:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmkoller/f10bcd6de81af75b4010 to your computer and use it in GitHub Desktop.
Save cmkoller/f10bcd6de81af75b4010 to your computer and use it in GitHub Desktop.

Git Cheat Sheet

The first two lists here are a super condensced version to give you easy access to the commands you'll be using all the time. For a fuller walkthrough of how to set up your project and keep it updated, read on below!

First Time Around:

  • cd <project_directory>
  • git init
  • git add -A
  • git commit -m "<your comment>"
  • git remote add origin <repo_url_from_github.com>
  • git push -u origin master

Subsequent Times:

  • git add -A
  • git commit -m "<your comment>"
  • git push origin master

Setting Up

(Do this when starting a project for the first time!)

Set things up on Github.com

  1. Go to Github.com
  2. Click the little plus sign next to your name (top right) and click “New Repository.” (A repository is basically the folder where a project’s files will live. Different projects should go in different repositories!)
  3. Fill out the repository name (something descriptive about your project). (NOTE: you can’t change this later, as far as I know.)
  4. Fill out the description (you can change this one later, hooray!)
  5. Leave everything else the same, and click “Create”.

Create a README.md file

This is something you are supposed to do.

  1. Go to your project directory on your computer.
  2. Make a file called README.md
  3. Write a short description of your project in that file.
  4. Yay, you’re done!

Use the command line to send stuff to Github.com!

This is where you have to start every time you have a totally new project, or have closed all your terminal windows and stuff since last working on your project.

  1. In your command line, get yourself inside your project directory.
  2. Initialize your Git repository: git init
  • Note! If you screwed up (like I did) and typed git init in the wrong directory, don’t panic and swear off Git forever (like I did). I don’t think it matters. To be safe, maybe just type git init again in the correct directory.
  1. Now Git is all running and ready to go. Woohoo! Time to get some files ready to send out there. Tell Git which files you want to get ready by typing: git add -A
  • This will add all your files (from the current directory) to the staging area, which is basically where good little files go and wait for the Git-mobile to take them away to the interwebs.
  1. Look at what’s going on in your staging area by typing: git status
  • This will tell you about the files on your staging area. If you’ve already put one version of these files up on Git, then the staging area will only keep track of files that have been changed since last time.
  1. Time to get things ready to send off! Type: git commit -m “<your comment here!>”
  • The Git-mobile has arrived, and all your little files have now boarded the vehicle and are ready to be carried up to the Interwebs. (If this is your first commit, make your comment something like “First commit” - apparently that’s best practice. Otherwise, your comment should be talking about what you’ve changed.)
  1. Next you have to tell the files where to go. This is basically programing the Git-mobile’s GPS. Type: git remote add origin <repository-URL>
  • You can get your repository URL by going back to Github.com, go to the new repository you created, and copy the link they provide you on the page. “origin” is basically just the name you are assigning this location. It doesn’t have to actually be “origin”, but that’s apparently just what everyone does.
  1. Time to fire up the Git-mobile and send it off to the Mothership! Type: git push -u origin master
  • This will send your files up to Github. You can view by them by refreshing your repository page on Github.com!

Subsequent Times

Once you've set up Github in your project directory, this is all you need to do to Github-ify your later changes!

  1. Add all your changes to the staging area by typing: git add -A
  2. Commit your changes: git commit -m “<your comment>”
  3. Send the changes off to Github! git push origin master
  4. ...That’s it! You’re done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment