G LogoMy GitHubProjectsGuides

A Beginner's Guide to Git

By Garen Tyler

This guide gives commands in the Linux / Unix format. They may or may not work on Windows systems.


1 - What is Git?

Git is a versioning control system that allows developers to collaborate and share code effectively.

A popular product based on Git is GitHub. GitHub is many things, including a Git server, a social network, and a web app. Using GitHub allows you to easily share your code.


2 - Git Vocabulary

Git has many terms, but many of them are simple. Services such as GitHub or GitLab share this vocabulary.

  • Repository - Often shortened to repo, a repository is a code project or codebase. Repositories can contain many files and many folders.
  • Commit - A commit is a collection of changes to a repo. Changes can be across multiple files.
  • Staging - Before adding changes to a commit, the changes must be staged in order to be included in the next commit.
  • Push - To add your changes to a remote repo that you have write access to.
  • Pull - To get the newest changes to a remote repo that you have read access to.
  • Clone - To download a copy of a remote repo locally. Changes you make to your copy do not affect the original.
  • Fork - To create your own version of a repo. You own this copy, and can make as many commits to it as you want. If you want to merge your fork with the original, you'll need to create a pull request.
  • Pull Request - To ask the owner of a repo to accept your changes.
  • Branch - A version of a repo. Repos can have many branches, with differing purposes and code.

3 - Using Git

Git has many clients and iterations, of which we will cover the CLI commands. If you understand the vocabulary, you should easily be able to use a GUI such as GitHub Desktop or Git GUI.

Git CLI Commands

  • Creating a repo - Type git init to create a repo in the current folder.
  • Cloning a repo - Type git clone repo to clone the repo. Change repo to the URL of a repository, such as https://github.com/ElementG9/Pivot.
  • Staging changes - After making changes, type git add . to stage all changes. Change the . to a file name to stage that file.
  • Committing changes - After staging your changes, type git commit -m "commit message" to commit your changes locally. Change commit message to something that describes what you changed in that commit. Bad commit messages can make it hard for you or others to see what you changed when reviewing the code later.
  • Pushing your changes - To push changes to a remote repo, type git push origin master. master is the default branch name. Change master to something else to push to a different branch.
  • Pulling changes - To pull changes to a repo, type git pull origin master. master can be changed to pull from a different branch.

4 - Questions

Have any questions, comments, or suggestions? Contact Garen by sending an email or visiting his GitHub.