Skip to Content

Git: An Introduction

Git is perhaps the most popular repository system today. Note that Git is not GitHub! GitHub is a hosted site of Git repositories and many other tools. Git is simply a repository-based revision control system.

Git

Revision control systems, also known as code repositories, source code control systems, and other names, are tools that manage the changing files that make up a project. They provide consistent and clear mechanisms for keeping track of all file changes and for documenting why those changes were made. In addition, they provide the capability to retrieve any historical version of any file in the project. You don’t have to copy your files to backup places anymore!

Git is extremely flexible, but this also makes it extremely complicated! Few Git users actually understand it. This is the reason that for years I have used the simpler Subversion for my courses; but Git seems to rule the world now.

There are many tutorials for Git, and the official site has extensive documentation: The online Git book there is great (chapters 1-2 will get you started). The available cheatsheet will be a good resource, too. Do not expect that you can get by with following copy+paste Git commands without understanding what they are doing; you will cheat yourself out of learning, and you will most likely make a mistake and lose a lot of work in the process. Learn Git!

Two important facts: one, Git does not automatically commit your modified files, you must “git add” every file that you want to commit; two, when you do “git commit”, you have only committed your changes to your local Git repository. You must “git push” the commit in order for it to go out to the remote repository (e.g, GitHub).

Most Frequent Git Commands

Command Description
git clone clones the remote repo into your local filespace (creates a local copy of the repo)
git add adds a local new/changed file into the next repo commit (can be used with a directory name but be careful!)
git commit -m ‘your commit message here’ commits changes of all repo files into the LOCAL copy of the repo (message quotes are needed)
git push pushes the committed changes to the local repo on to the remote repo
git pull pulls changes made to the remote repo into the local repo (fetch+merge)

Remote Repo (e.g., Github) Interaction

The picture below captures the main data flow interaction as you use Git and a remote repository such as on Github:

Git repository interaction

The main ideas in the image above are these: 1) “git commit” does not push anything to Github, only into your local repository copy 2) “git clone” creates both the local repository copy and your workspace; your workspace is actually what you see in your files, the local repository is hidden in a “.git” subdirectory which you don’t normally see and never use directly as files! You can use “git checkout” to change your workspace to other versions of your repo files (branches, old versions, etc.). In most class work you should never need to use “git checkout”, until you use branches in your project.

Tutorials and Cheatsheets

The Git home has extensive documentation including a PDF cheatsheet.

Atlassian has a bunch of Git tutorials and has a nicer cheatsheet

GitLab (something similar to GitHub but locally installable) has great documentation on using Git and has a very nice PDF cheatsheet.

GitHub also has plenty of documentation.

Workflows

Atlassian has a nice tutorial on different workflows that you can use with Git.

Other Resources

If you become a very active GitHub user, you will definitely want the GitHub Command Line tools.

Git for Windows (and also here) seems to be the most popular Git toolset for the Windows platform. It includes a “git bash” shell that lets you use git command-line tools.

TortoiseGit also appears to be a popular Windows Git tool.

It also seems that PowerShell is something you should definitely learn to use if you are a Windows user.

Prof. Michael Ernst has a good resource on Repository Best Practices along with other good advice.