Skip to content

Instantly share code, notes, and snippets.

@hfaerber
Last active May 13, 2019 04:19
Show Gist options
  • Save hfaerber/e4f0f140c82759876f210050b48a6e04 to your computer and use it in GitHub Desktop.
Save hfaerber/e4f0f140c82759876f210050b48a6e04 to your computer and use it in GitHub Desktop.

Beginner's Guide to Git

What is Git?

Git is a VCS that allows you to work locally and save (commit) snapshot versions of a file (repository) so that you can reference or revert back to them.

So what is GitHub then? Different name for the same thing?

Nope. GitHub is a website that hosts repositories (repos) remotely so that commits can be accessed by multiple people who can then work on and update them simultaneously without losing or writing over anyone's changes.

How do you do it? The Git thing

  1. You initialize tracking. git init
  2. You add to the staging area. git add
  3. You commit (aka save as a kind of freeze frame or snapshot) for the first time. git commit -m "Initial commit"
  4. You work on a file more until you're ready to set it up to be committed again. You add it to the staging area. git add
  5. You commit the updated file/changes. git commit -m "Clear, brief, present tense documentation of changes here"
  6. You keep working and updating and staging and committing different snapshot of the repo.
git init 
git add
git commit -m "Initial commit"
git add
git commit -m "Add code example"

Ok, so how does GitHub come into play?

  • You can set up your repo on GitHub so that it is housed there. This allows for more cool stuff to be possible.
  • You can pull and git push commits between your local Git and the remote repo in GitHub.
  • You can create and work from branches that are extended from your original master repo. This keeps the original master intact while allowing you to branch off and make changes. You can add and remove branches as you need and no longer need them.
  • Others can clone your work and dive into working on it as well without effecting your original master.
  • Others can work simultaneously on parts of the repo by pulling the latest commits, making their own updates, and pushing their updated commit back to GitHub. Even if you are simulaneaously working on the same branch or section, one's work doesn't overwrite the other's; they can be merged so nothing is lost.

shruggie

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