Simple git example (local repository)

0. Configure your information:

git config --global user.name "Mr User the user"
git config --global user.email "[email protected]"

You can also configure an editor:

git config --global core.editor 'vim'

1. Create a repository

mkdir testproject
cd testproject
git init

2. Commit a file

touch testfile
git add testfile
git commit

3. Making a release branch

git branch RB_1.0 master

While you’ve created a release branch, you’re still currently on the master branch. So if you make a change here:

touch testfile2
git add testfile2
git commit

That file will NOT be in the release branch (RB_1.0).

4. Switching between the master branch and the release branch.

Unlike, SVN which stores different branches in different directories, git uses a command to switch your directory between branches. Slightly confusingly this command is called “checkout”.

git checkout RB_1.0

If you want, you can make changes to RB_1.0, they wont be refected elsewhere.

touch rb1file
git add rb1file
git commit

5. Releasing

Create a tag:

git tag 1.0 RB_1.0

List all tags:

git tag

6. Merging

Merge changes from RB_1.0 on to master:

git checkout master
git rebase RB_1.0

7. Delete a branch

It seems to be git practice to delete branches, you can always branch from the tag.

git branch -d RB_1.0

8. Creating a tarball

git archive --format=tar --prefix=testproject1 1.0 > ~/testproject1.tar

9. Changing a file!

This may be slightly different than you were expecting. You can’t just edit the file and type “git commit” rather, you need to add then commit. For example, after editing testfile:

git add testfile
git commit

Git creates commits in two stages like this. The first add “stages” the change and commit commits it. You can do multiple adds before the commit. The idea is to let you get everything organised before finally performing the commit.

Notes on git

There are no version numbers. A revision is identified by its hash.

master is like trunk in SVN/CVS.

checkout, doesn’t really mean checkout. It mean switch between branches.

You can also branch from tags the same way you branch from master.