Git is a Distributed Version Control System (DVCS). It tracks changes to a project over time (and by many contributors), which facilitates rollbacks, history inspection, and merges. It's a command line tool, but there are many GUI programs which interact with it.
Git tracks the files in a given folder, called the repository or repo. Each unit of work is called a commit (KUH-mit), or a revision.
Git can be installed from git-scm.com. While Git itself is a command-line tool, it also comes with git gui
for staging and committing, and gitk
for browsing history.
There are also free and paid third-party GUIs, some of which are listed here. Many IDEs and editors include their own copy of Git, but some require it to be installed separately.
After initializing the repository, working with Git involves a few steps that you'll repeat often:
- Do your work and save your files.
- Stage your changes so Git knows what to remember.
- Commit those changes with a message about what you've done.
- Optionally, "push" those changes to share your work with others.
Even if you're using a GUI, you should be familiar with the basic commands of Git. This is more or less what the GUIs are doing under the hood.
All of these commands operate on one repository at a time.
git init
creates a Git repository in the current directory. This creates a hidden folder called .git
, where Git tracks the state of your work. Don't mess with that folder carelessly.
git status
prints the current state of the repository. Whenever you're not sure what you've staged or committed, use this command.
git add
stages the files that match the given pattern. You can use a file's name, or use a wildcard (*
character) to match many files at once. A file can't be committed unless it is staged.
git commit
saves all the files you've staged as a commit in the project's history. You will be promted for a message, which should explain the changes to other developers (and your future self, too).
git push
sends your changes to a remote server (more info). You might use such a server for backup purposes, or as the single "master copy" for everyone on a team.
-
Again, Git's website has great resources for learning more about Git.
-
Here's a glossary of terms related to Git and GitHub.
-
GitHub is the biggest provider of Git hosting. You get unlimited public repos for free.
-
Bitbucket is another provider of hosting, and they offer unlimited private repos for free.
-
And GitLab offers both types for free. It's just not as popular for some reason.
Copyright Tyler Mumford, 2015. Use this intro however you like. If you find it valuable, please let me know; it would make me very happy.