Git Basic Reference
The git tool allows developers to track their changes to application code over time. This is especially valuable for recovering a working version of an application if something goes wrong. While git includes many advanced features for team collaboration and parallel feature development, this guide will focus on the basics - those commands that are most useful to a solo developer.
After reviewing the terminology specific to git and an introduction to GitHub, you will find these commands:
- git clone
- git status
- git add
- git commit
- git push
- git pull
- git restore
Process
The basic git process looks something like this...
- Start work on one, two, or a few code files.
- Collect the files that you want to back up together. In git terms, this is referred to as "preparing a commit". It involves adding new and modified files into the collection.
- Lock in this set of changes by "committing" them.
All of these steps happen on your local machine - no one else can see them.
To share files with others, or store them remotely, so you can recover them even if your machine becomes unusable, you need to "push" to a server. If you are collaborating or using code shared by other developers, then you'll need to "pull" changes from the remote server to your local machine.
Terminology
In order to most effectively use git, there are a few terms you need to understand.
- Add - Include a file in git which wasn't there before
- Clone - Create a local copy of a git repository which is hosted in an online service (e.g. GitHub)
- Commit (verb) - To lock in a set of changes
- Commit (noun) - A set of changes that has been locked in
- Modified - Status of a file that has changes in it
- Origin - Default name for the remote server
- Pull - Retrieve the latest files from online service (a.k.a. "pull from origin")
- Push - Send the latest files to the online service (a.k.a. "push to origin")
- Remove - Take a file out of git which was previously added
- Repository - Collection of files in git that belong together - called "repo", for short; for example,
- Coding project
- Simple software application
- Complex applications may be stored in multiple repos
- Restore - Undo changes to a file taking it back to the previous commit
- Staged - Set of files ready to be locked into a commit
You'll learn more about additional terms (such as branch, log, staging area, working directory, and more).