Skip to content

Instantly share code, notes, and snippets.

@itsgreggreg
Last active August 29, 2015 14:18
Show Gist options
  • Save itsgreggreg/4ae973c1c235601c7bb3 to your computer and use it in GitHub Desktop.
Save itsgreggreg/4ae973c1c235601c7bb3 to your computer and use it in GitHub Desktop.
An quick tour of git and it's commands

What is git?

git is a tool for managing programming projects. A programming project is a collection of related files and folders inside 1 main directory that is named after our project. When a programming project is using git, that project is said to be a repository. Sometimes people say the files are in git.

Using git allows us to do many things:

  • We can easily share our code with others.
  • We can easily collaborate with others on our project.
  • Everyone can easily have the most recent files in our project.
  • We can see a history of our project.
  • We can recover old files or parts of files.
  • We can work on the same files as others at the same time.
  • We can see what work other people have done in our project.
  • We can easily store our code online.
  • We can be organized!!

How does git work?

We make git work! Git rarely does anything by itself, we almost always have to tell it what to do.

This section is going to have many commands that look like this. While there are many graphical applications that make using git a little simpler, here we are going to be focusing on using git with a unix-like terminal aka command line.

When we want to turn a project into a repository, we have to run git init. When we want to prepare a snapshot to be saved forever we have to run git add. When we want to save our snapshot forever we have to run git commit. And when we want to collaborate with others we have to run git pull and git push. Those are all the basic commands that we will need to collaborate on our project and store our code online. I lied, there's also git status but that one's pretty easy and doesn't do anything but show you some information.

Git stores our project as a series of snapshots.

What is a snapshot?

Since we are going to be collaborating on our project with other people, we need an easy way to send them our files and be organized about it. Instead of sending our files individually every time something changes we build snapshots of our whole project and send these snapshots. And because we can change multiple files per snapshot and give our snapshot a name we can stay organized with our changes. These snapshots are also called commits.

How do we use git?

Starting a repository

When we want to turn a project into a repository we run:
git init

Building snapshots

When we want to add a file to a snapshot we run:
git add file_name

Saving snapshots

When we have files in a snapshot and we want to save that snapshot forever we run:
git commit -m"Some name for your snapshot"

Sharing code

When we want to push our snapshots to the internet so we can share them we run:
git push

Getting other people's code

When we want to see what other people have done we run:
git pull

Seeing what git sees

If at any time you want to see what git sees, for example what git thinks the snapshot you're currently creating looks like, you run:
git status
This command doesn't change anything and you should run it all the time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment