wiki:Basic Git Usage

Version 1 (modified by Joe Ciccone, 11 years ago) (diff)


This page contains a basic tutorial for working with git. There aren't any advanced concepts here, just the basics. In this tutorial we'll be working with a testing git repo and fake files.

Its always a good thing to remember that while working with Git is a decentralized VCS, even though you may choose to push changes all to one server, you don't have to. Each repo contains a full history and set of objects in the .git directory.

You will also only see a .git directory in the top level unlike svn where you have .svn in each sub directory as well as the top level.

Unlike svn, git uses hashes to identify commits instead of revision numbers.

These are just some basic tasks, the man pages can go into a lot more detail.

Initializing a Git Repo

Create a empty working directory:

mkdir git-tutorial
cd git-tutorial

Initialize the local Git Repo:

git init

Committing files to the Repo

Lets create a test file:

echo "Test Data" > testfile

Stage the file to be included into the next commit:

git add testfile

Finally commit the file to the repo:

git commit -m "Add a test file"

Viewing changes to files before committing them

First lets make a change to our test file:

echo "Different Test Data" > testfile

View the changes:

git diff

You could also execute the following or something similar:

git diff testfile

Listing files with changes

You can use the following command to list the status of all files not ignored by Git:

git status

You can also use the command on a path, the same as git diff.

Revert a file back to a specified commit

In this case we want to revert to the current working ref, so we wont specify one:

git checkout testfile

Reverting the entire working tree

You can use the following command to revert the entire working tree to the last commit in the branch you're working with:

git reset --hard